Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL cStrTimestamp
LOCAL oDateTime
LOCAL nBLocalTimezone
LOCAL oDt

//  Let's say we have a timestamp string such as 2016-11-11T14:32:17.0908971Z
cStrTimestamp := "2016-11-11T14:32:17.0908971Z"

oDateTime := CreateObject("Chilkat.CkDateTime")
oDateTime:SetFromTimestamp(cStrTimestamp)

//  Get a DtObj in the local timezone.
nBLocalTimezone := 1
oDt := CreateObject("Chilkat.DtObj")
oDateTime:ToDtObj(nBLocalTimezone, oDt)

//  Get the individual date/time components
? "-- Local Time --"
? "Year: " + Str(oDt:Year)
? "Month: " + Str(oDt:Month)
? "Day: " + Str(oDt:Day)
? "Hour: " + Str(oDt:Hour)
? "Minutes: " + Str(oDt:Minute)
? "Seconds: " + Str(oDt:Second)

//  Get a DtObj in the GMT/UTC timezone.
nBLocalTimezone := 0
oDateTime:ToDtObj(nBLocalTimezone, oDt)

//  Get the individual date/time components
? "-- UTC Time --"
? "Year: " + Str(oDt:Year)
? "Month: " + Str(oDt:Month)
? "Day: " + Str(oDt:Day)
? "Hour: " + Str(oDt:Hour)
? "Minutes: " + Str(oDt:Minute)
? "Seconds: " + Str(oDt:Second)

oDateTime:destroy()
oDt:destroy()