I have this code in an HTML page:
alert(JSON.stringify(new Date()));
I\'m including the latest json2.js (2009-09-29 version) in my page to
You could also adjust json2.js a bit to always use its own Date.prototype.toJSON
instead of a possible native one. Here I uncommented two lines and it works correctly:
// if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
return isFinite(this.valueOf()) ?
this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};
// }