JSON does not support dates as their own recognized data type. Dates are serialized to strings using one of several formats when serializing (depending on the serializer), and are only sometimes deserialized to date objects when deserializing (browsers never do this by default, it's not part of the JSON spec).
The format looks like how .NET serializes dates to string within JSON. On the receiving side before working with the deserialized JSON you need to convert the date strings to date object. Neither Angular or JSON.parse
do this for you.
You can inject custom parsing using $httpProvider.defaults.transformResponse
.
https://docs.angularjs.org/api/ng/service/$http
A JSON.parse
implementation that includes support for dates is available here:
http://weblog.west-wind.com/posts/2014/Jan/06/JavaScript-JSON-Date-Parsing-and-real-Dates
if (window.JSON && !window.JSON.dateParser) {
var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
var reMsAjax = /^\/Date\((d|-|.*)\)[\/|\\]$/;
JSON.dateParser = function (key, value) {
if (typeof value === 'string') {
var a = reISO.exec(value);
if (a)
return new Date(value);
a = reMsAjax.exec(value);
if (a) {
var b = a[1].split(/[-+,.]/);
return new Date(b[0] ? +b[0] : 0 - +b[1]);
}
}
return value;
};
}
var date = JSON.parse(json,JSON.dateParser);
console.log(date);