I still get invalid date with new Date("2011-09-03 02:23:24".replace(" ", "T")) with Safari. I realize this works in firefox, but I'm looking for a cross-browser solution
Last edited by Marius Miliunas; 09-06-2011 at 03:40 PM.
function parseDateFormat(input, format) {
format = format || 'YYYY-MM-DD hh-mm-ss'; // default format
var parts = input.match(/(\d+)/g),
i = 0, fmt = {};
// extract date-part indexes from the format
format.replace(/(YYYY|DD|MM|hh|mm|ss)/g, function(part) { fmt[part] = i++; });
return new Date(parts[fmt['YYYY']], parts[fmt['MM']]-1, parts[fmt['DD']], parts[fmt['hh']], parts[fmt['mm']], parts[fmt['ss']]);
}
parseDateFormat(2011-09-06 02:13:45)//Tue Sep 06 2011 02:13:45 GMT-0400 (EDT)
Take care. It's a local client date !
For me this script give (with quote on the date string) Tue Sep 6 02:13:45 UTC+0200 2011
It's not exactly the same date that Tue Sep 06 2011 02:13:45 GMT-0400
My browser is Internet Explorer 8 (Version 8.0.6001.18702) witch give
Tue Sep 6 02:13:45 UTC+0200 2011
Other current browsers :
Mozilla FireFox (6.0.1)
Tue Sep 06 2011 02:13:45 GMT+0200
Google Chrome (13.0.782.201 m)
Tue Sep 06 2011 02:13:45 GMT+0200 (Paris, Madrid (heure d'été))
Safari for windows (5.0.5 7533.21.1)
Tue Sep 06 2011 02:13:45 GMT+0200 (Paris, Madrid (heure d'été))
Opéra (11.51 1087)
Tue Sep 06 2011 02:13:45 GMT+0200
Microsoft is alone, but right with UTC (See NOAA).
I would say replace the GMT with UTC using a regexp because what it boils down to is that GMT is just milliseconds difference from UTC, which I don't really find important when it comes to web programming
Bookmarks