Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Problem with Date() in IE (but not FF)

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,015
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    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??

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    Code:
    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);
    Last edited by mrhoo; 06-03-2009 at 07:22 PM.

  • #4
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    >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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •