Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Parse a Microsoft JSON Date (MS AJAX Date)

See more JSON Examples

Demonstrates how to parse a Microsoft JSON Date, also known as an MSAJAX date.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJson
LOCAL oDt
LOCAL nBLocal
LOCAL oDtObj

nSuccess := 0

//  Parse Microsoft JSON Dates (AJAX Dates)
oJson := CreateObject("Chilkat.JsonObject")

nSuccess := oJson:Load('{ "AchievementDate":"/Date(1540229468330-0500)/"}')

oDt := CreateObject("Chilkat.CkDateTime")
nSuccess := oJson:DateOf("AchievementDate", oDt)
IF (nSuccess != 1)
    ? "Unable to parse a date/time."
    oJson:destroy()
    oDt:destroy()
    RETURN
ENDIF

//  Show the date in different formats:
nBLocal := 1
? "RFC822: " + oDt:GetAsRfc822(nBLocal)
? "Timestamp: " + oDt:GetAsTimestamp(nBLocal)
? "YYYY-MM-DD: " + oDt:GetAsIso8601("YYYY-MM-DD", nBLocal)

//  Get integer values for year, month, day, etc.
oDtObj := CreateObject("Chilkat.DtObj")
oDt:ToDtObj(nBLocal, oDtObj)

? "year: " + Str(oDtObj:Year)
? "month: " + Str(oDtObj:Month)
? "day: " + Str(oDtObj:Day)
? "hour: " + Str(oDtObj:Hour)
? "minute: " + Str(oDtObj:Minute)
? "seconds: " + Str(oDtObj:Second)

//  Sample output:
//  RFC822: Mon, 22 Oct 2018 17:31:08 -0500
//  Timestamp: 2018-10-22T17:31:08-05:00
//  YYYY-MM-DD: 2018-10-22
//  year: 2018
//  month: 10
//  day: 22
//  hour: 17
//  minute: 31
//  seconds: 8

oJson:destroy()
oDt:destroy()
oDtObj:destroy()