Mark Struzinski Mark Struzinski - 11 months ago 95
ASP.NET (C#) Question

How do I format a Microsoft JSON date?

I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like this:


From someone totally new to JSON - How do I format this to a short date format? Should this be handled somewhere in the jQuery code? I've tried the
plugin using
without any success.

FYI: Here's the solution I came up with using a combination of the answers here:

function getMismatch(id) {
{ MismatchId: id },

function (result) {

return false;

function formatJSONDate(jsonDate) {
var newDate = dateFormat(jsonDate, "mm/dd/yyyy");
return newDate;

This solution got my object from the callback method and displayed the dates on the page properly using the date format library.

Answer Source

Eval is not necessary. This will work fine:

var date = new Date(parseInt(jsonDate.substr(6)));

The substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end. The resulting number is passed into the Date constructor.

EDIT: I have intentionally left out the radix (the 2nd argument to parseInt); see my comment below. Also, I completely agree with Rory's comment: ISO-8601 dates are preferred over this old format -- so this format generally shouldn't be used for new development. See the excellent Json.NET library for a great alternative that serializes dates using the ISO-8601 format.

For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:

var date = new Date(jsonDate); //no ugly parsing needed; full timezone support