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

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.DtObj;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        // Parse Microsoft JSON Dates (AJAX Dates)
        JsonObject json = new JsonObject();

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

        DateTime dt = new DateTime();
        try {
            json.dateOf("AchievementDate", dt);
        } catch (ChilkatException e) {
            System.out.println("Unable to parse a date/time.");
            return;
        }

        // Show the date in different formats:
        boolean bLocal = true;
        System.out.println("RFC822: " + dt.getAsRfc822(bLocal));
        System.out.println("Timestamp: " + dt.getAsTimestamp(bLocal));
        System.out.println("YYYY-MM-DD: " + dt.getAsIso8601("YYYY-MM-DD", bLocal));

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

        System.out.println("year: " + dtObj.getYear());
        System.out.println("month: " + dtObj.getMonth());
        System.out.println("day: " + dtObj.getDay());
        System.out.println("hour: " + dtObj.getHour());
        System.out.println("minute: " + dtObj.getMinute());
        System.out.println("seconds: " + dtObj.getSecond());

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