Sample code for 30+ languages & platforms
Node.js

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 Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    //  Parse Microsoft JSON Dates (AJAX Dates)
    var json = new chilkat.JsonObject();

    success = json.Load("{ \"AchievementDate\":\"/Date(1540229468330-0500)/\"}");

    var dt = new chilkat.CkDateTime();
    success = json.DateOf("AchievementDate",dt);
    if (success !== true) {
        console.log("Unable to parse a date/time.");
        return;
    }

    //  Show the date in different formats:
    var bLocal = true;
    console.log("RFC822: " + dt.GetAsRfc822(bLocal));
    console.log("Timestamp: " + dt.GetAsTimestamp(bLocal));
    console.log("YYYY-MM-DD: " + dt.GetAsIso8601("YYYY-MM-DD",bLocal));

    //  Get integer values for year, month, day, etc.
    var dtObj = new chilkat.DtObj();
    dt.ToDtObj(bLocal,dtObj);

    console.log("year: " + dtObj.Year);
    console.log("month: " + dtObj.Month);
    console.log("day: " + dtObj.Day);
    console.log("hour: " + dtObj.Hour);
    console.log("minute: " + dtObj.Minute);
    console.log("seconds: " + dtObj.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

}

chilkatExample();