jQuery & JavaScript

Convert a JSON date like /Date(1700000000000)/ to a local date in JavaScript

jQuery & JavaScript · · Published 2026-09-18

Call an ASP.NET page method or an ASMX web service from jQuery and a DateTime comes back as a strange string: "/Date(1730707200000)/". That is the Microsoft JSON date format used by JavaScriptSerializer and DataContractJsonSerializer. The number is milliseconds since 1 January 1970 UTC, which JavaScript's Date understands directly.

Parsing /Date(…)/

function parseMsJsonDate(value) {
  // matches /Date(1730707200000)/ and /Date(1730707200000+0100)/
  var m = /^\/Date\((-?\d+)([+-]\d{4})?\)\/$/.exec(value);
  return m ? new Date(Number(m[1])) : null;
}

var d = parseMsJsonDate("/Date(1730707200000)/");
console.log(d.toISOString());                       // 2024-11-04T08:00:00.000Z
console.log(d.toLocaleString());                    // in the visitor's time zone and language

The optional +0100 suffix, produced by DataContractJsonSerializer for local times, describes the original offset; the millisecond value is still UTC, so it can be ignored for display in the visitor's zone.

With jQuery AJAX

$.ajax({
  type: "POST",
  url: "Orders.aspx/GetLatest",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json"
}).done(function (res) {
  var order = res.d;                         // page methods wrap results in "d"
  var created = parseMsJsonDate(order.CreatedAt);
  $("#created").text(created.toLocaleDateString(undefined, { dateStyle: "medium" }));
});

Calling page methods is explained in Call a server-side method with jQuery AJAX.

Watch the DateTimeKind on the server

JavaScriptSerializer converts local DateTime values to UTC before writing the milliseconds, and treats Unspecified values (typical for values read from SQL Server datetime columns) as local time. If the server runs in a different time zone from the one the data was recorded in, displayed times shift by hours. Store and transmit UTC: mark values with DateTime.SpecifyKind(value, DateTimeKind.Utc) when you know they are UTC.

Prefer ISO 8601

Modern serialisers write dates as ISO 8601 strings: "2024-11-04T08:00:00Z". Both Json.NET (its default since version 4.5) and System.Text.Json do so, and JavaScript parses them natively:

var d = new Date("2024-11-04T08:00:00Z");

Be careful with strings that have no offset: new Date("2024-11-04T08:00:00") is interpreted as local time, while a date-only string "2024-11-04" is interpreted as UTC midnight. Always include Z or an offset for timestamps.

On the server, an ASP.NET Web API or a handler serialising with Json.NET can send ISO dates directly; for page methods, you can return a pre-formatted string such as order.CreatedUtc.ToString("o") in a DTO.

Formatting for display

var fmt = new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" });
$("time[data-utc]").each(function () {
  var d = new Date($(this).data("utc"));          // ISO string with Z
  if (!isNaN(d)) $(this).text(fmt.format(d));
});

Creating the formatter once and reusing it is faster than calling toLocaleString with options for every element.

Official documentation