Sample code for 30+ languages & platforms
Delphi DLL 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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
json: HCkJsonObject;
dt: HCkDateTime;
bLocal: Boolean;
dtObj: HCkDtObj;

begin
success := False;

//  Parse Microsoft JSON Dates (AJAX Dates)
json := CkJsonObject_Create();

success := CkJsonObject_Load(json,'{ "AchievementDate":"/Date(1540229468330-0500)/"}');

dt := CkDateTime_Create();
success := CkJsonObject_DateOf(json,'AchievementDate',dt);
if (success <> True) then
  begin
    Memo1.Lines.Add('Unable to parse a date/time.');
    Exit;
  end;

//  Show the date in different formats:
bLocal := True;
Memo1.Lines.Add('RFC822: ' + CkDateTime__getAsRfc822(dt,bLocal));
Memo1.Lines.Add('Timestamp: ' + CkDateTime__getAsTimestamp(dt,bLocal));
Memo1.Lines.Add('YYYY-MM-DD: ' + CkDateTime__getAsIso8601(dt,'YYYY-MM-DD',bLocal));

//  Get integer values for year, month, day, etc.
dtObj := CkDtObj_Create();
CkDateTime_ToDtObj(dt,bLocal,dtObj);

Memo1.Lines.Add('year: ' + IntToStr(CkDtObj_getYear(dtObj)));
Memo1.Lines.Add('month: ' + IntToStr(CkDtObj_getMonth(dtObj)));
Memo1.Lines.Add('day: ' + IntToStr(CkDtObj_getDay(dtObj)));
Memo1.Lines.Add('hour: ' + IntToStr(CkDtObj_getHour(dtObj)));
Memo1.Lines.Add('minute: ' + IntToStr(CkDtObj_getMinute(dtObj)));
Memo1.Lines.Add('seconds: ' + IntToStr(CkDtObj_getSecond(dtObj)));

//  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

CkJsonObject_Dispose(json);
CkDateTime_Dispose(dt);
CkDtObj_Dispose(dtObj);