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 might want to consider beefing up the server, to recognize any valid ISO 8601 time format:
'2010-02-08T03:37:34.327Z'
'2010-02-08T03:38:06Z'
'2010-02-08T03:38+01:00'
'2010-02-08T03:34:18-05:00'
'2010-02-08T03:34Z'
'2010-02-08'
This is a method to convert any iso string to a javascript date object. It could be used on the server with a little translation:
Date.from_iso= function(s){
var D, M= [], hm, min= 0, d2,
Rx= /([\d:]+)(\.\d+)?(Z|(([+\-])(\d\d):(\d\d))?)?$/;
D= s.substring(0, 10).split('-');
if(s.length> 11){
M= s.substring(11).match(Rx) || [];
if(M[1]) D= D.concat(M[1].split(':'));
if(M[2]) D.push(Math.round(M[2]*1000));// msec
}
for(var i= 0, L= D.length; i