...

View Full Version : Problem with Date() in IE (but not FF)



snoodle
06-03-2009, 04:28 PM
I know there're plenty of ways to get around this, but having come up empty after googling for solutions I was curious if anyone is familiar with this issue.

After fetching a timestamp via sql, I return to javascript to do the formatting. Actually, I was first doing a bit of formatting in php to change from yyyy mm dd hh:mm (as saved in db) to mm dd yyyy hh:mm as I found the 1st not to work with the Date() function in FF.

Consider the following...

var date_from_server = "06 03 2009 01:37";
var jsDate = Date(date_from_server);

In FF jsDate is "Thu Jun 03 1909 01:37:00 GMT-0700 (Pacific Daylight Time)".

In IE7 jsDate is NaN.

I've tried a few different formats. Does IE7,s Date() function not allow an arg at all or only of a certain format? I was surprised to not find a bunch of google results for the issue as is usually the case when solving cross browser problems.

Philip M
06-03-2009, 07:10 PM
In IE6 I get:-

Wed Jun 03 19:08:40 2009

Why does FF say that June 3 is a Thursday and the year 1909??

mrhoo
06-03-2009, 07:15 PM
Date.fromISO= function(s){
var i= 0, A= s.split(/\D+/);
while(i++<7){
if(!A[i]) A[i]= 0;
else A[i]= parseInt(A[i], 10);
}
--A[1];
return new Date(Date.UTC(A[0], A[1], A[2], A[3], A[4], A[5]));
}
var s='2009-06-01 07:48:45';
var s2= Date.fromISO(s);
alert('ISO= '+s+'\nlocal Date returned:\n'+s2);

snoodle
06-03-2009, 07:32 PM
>Why does FF say that June 3 is a Thursday and the year 1909??
Oops, sorry. I was spitting out a bunch of debugging lines and copied the wrong one.


>Date.fromISO= function(s){
Thanks! My next step was to "manually" parse, but as far as what's goin' on with IE, is it just another IE non-W3C standard deal? Actually, in looking at the W3C doc I don't recall anything about an arg for Date().

Who knows. Thanks again for the code. Now on to bigger and juicier bugs...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum