Skip to content

Instantly share code, notes, and snippets.

@kristofferh
Created March 16, 2011 17:39
Show Gist options
  • Save kristofferh/872902 to your computer and use it in GitHub Desktop.
Save kristofferh/872902 to your computer and use it in GitHub Desktop.
Convert a jsonDate (something like /Date(1284604200000-0700)/, .NET likes this) to something more human readable
/**
* convert a JSONDATE (something like /Date(1284604200000-0700)/) to something more human readable
*/
function jsonDate(str) {
return new Date(parseInt(str.replace(/\/Date\((.*?)\)\//gi, "$1"), 10));
}
// jsonDate('/Date(1284604200000-0700)/');
// -> Wed Sep 15 2010 19:30:00 GMT-0700 (PDT)
@dandean
Copy link

dandean commented Mar 16, 2011

Also,

blah blah blah blah blah.

Dan

@kristofferh
Copy link
Author

You're right, parseInt is tossing the '-0700'. I guess I should have checked that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment