AutoIt
AutoIt
How to Parse a TimeStamp (such as 2016-11-11T14:32:17.0908971Z)
Timestamps are frequently used in REST API responses. This example demonstrates how to parse a timestamp string to get at the date/time components in the local timezone or in the GMT/UTC timezone.Chilkat AutoIt Downloads
; Let's say we have a timestamp string such as 2016-11-11T14:32:17.0908971Z
Local $strTimestamp = "2016-11-11T14:32:17.0908971Z"
$oDateTime = ObjCreate("Chilkat.CkDateTime")
$oDateTime.SetFromTimestamp($strTimestamp)
; Get a DtObj in the local timezone.
Local $bLocalTimezone = True
$oDt = ObjCreate("Chilkat.DtObj")
$oDateTime.ToDtObj $bLocalTimezone,$oDt
; Get the individual date/time components
ConsoleWrite("-- Local Time --" & @CRLF)
ConsoleWrite("Year: " & $oDt.Year & @CRLF)
ConsoleWrite("Month: " & $oDt.Month & @CRLF)
ConsoleWrite("Day: " & $oDt.Day & @CRLF)
ConsoleWrite("Hour: " & $oDt.Hour & @CRLF)
ConsoleWrite("Minutes: " & $oDt.Minute & @CRLF)
ConsoleWrite("Seconds: " & $oDt.Second & @CRLF)
; Get a DtObj in the GMT/UTC timezone.
$bLocalTimezone = False
$oDateTime.ToDtObj $bLocalTimezone,$oDt
; Get the individual date/time components
ConsoleWrite("-- UTC Time --" & @CRLF)
ConsoleWrite("Year: " & $oDt.Year & @CRLF)
ConsoleWrite("Month: " & $oDt.Month & @CRLF)
ConsoleWrite("Day: " & $oDt.Day & @CRLF)
ConsoleWrite("Hour: " & $oDt.Hour & @CRLF)
ConsoleWrite("Minutes: " & $oDt.Minute & @CRLF)
ConsoleWrite("Seconds: " & $oDt.Second & @CRLF)