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

React Native
import { CkDateTime, DtObj, JsonObject } from '@chilkat/react-native'

function chilkatExample() {
  // Parse Microsoft JSON Dates (AJAX Dates)
  const json = new JsonObject();

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

  const dt = new CkDateTime();
  try {
    json.dateOf('AchievementDate', dt);
  } catch {
    console.log('Unable to parse a date/time.');
    return;
  }

  // Show the date in different formats:
  const 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.
  const dtObj = new 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
}