Skip to content

Instantly share code, notes, and snippets.

@finico
Created October 21, 2015 12:24
Show Gist options
  • Save finico/62b8cab8e3758af4af77 to your computer and use it in GitHub Desktop.
Save finico/62b8cab8e3758af4af77 to your computer and use it in GitHub Desktop.
JSON date parser
function dateParser(key, value) {
if (typeof value === 'string') {
var matched = /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)$/.exec(value);
if (matched) {
return new Date(value);
}
if (!JSON.parseMsAjaxDate) {
return value;
}
matched = /^\/Date\((d|-|.*)\)[\/|\\]$/.exec(value);
if (matched) {
var msMatched = matched[1].split(/[-+,.]/);
return new Date(msMatched[0] ? +msMatched[0] : 0 - +msMatched[1]);
}
}
return value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment