B4X
B4X
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 B4X Downloads
' Let's say we have a timestamp string such as 2016-11-11T14:32:17.0908971Z
Dim strTimestamp As String = "2016-11-11T14:32:17.0908971Z"
Dim dateTime As ChilkatDateTime
dateTime.Initialize
dateTime.SetFromTimestamp(strTimestamp)
' Get a DtObj in the local timezone.
Dim bLocalTimezone As Boolean = True
Dim dt As ChilkatDtObj
dt.Initialize
dateTime.ToDtObj(bLocalTimezone, dt)
' Get the individual date/time components
Log("-- Local Time --")
Log("Year: " & dt.Year)
Log("Month: " & dt.Month)
Log("Day: " & dt.Day)
Log("Hour: " & dt.Hour)
Log("Minutes: " & dt.Minute)
Log("Seconds: " & dt.Second)
' Get a DtObj in the GMT/UTC timezone.
bLocalTimezone = False
dateTime.ToDtObj(bLocalTimezone, dt)
' Get the individual date/time components
Log("-- UTC Time --")
Log("Year: " & dt.Year)
Log("Month: " & dt.Month)
Log("Day: " & dt.Day)
Log("Hour: " & dt.Hour)
Log("Minutes: " & dt.Minute)
Log("Seconds: " & dt.Second)