Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post
    Hi
    I have this code to show updates on my webpages, but it gives US dates.

    is this the fault of the host server?

    <script>
    document.write('Page last updated')
    </script>
    <script>
    var modifieddate=document.lastModified
    document.write(modifieddate)
    </script>

    Regards
    Braddy
    If you are a fool at forty, you will always be a fool

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by braddy60 View Post
    is this the fault of the host server?
    It could well be that the browser interprets the date to local format.

    To quickly test the current page (any page), you can paste this bookmarklet into the address bar and press Enter:

    Code:
    javascript:void(alert(document.lastModified));
    In a few tests, I only get a U.S. format. It's possible that this is driven by my OS "region" settings, but that's just a guess.

    For maximum control, you can construct your own date using the getMonth(), getDate(), and getFullYear() functions. E.g.,

    Code:
    var d = new Date(document.lastModified); 
    var df = d.getDate() + "/" + d.getMonth() + "/" + d.FullYear();
    Maybe a more recent version of JavaScript, or one of the popular libraries, has a more convenient function for that...

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,191
    Thanks
    48
    Thanked 986 Times in 916 Posts
    If I run that code on my system with the date format dd/mm/yyyy I get a result mm/dd/yyyy - Firefox V3.

    cheers, Paul

  4. #4
    New Lounger
    Join Date
    Dec 2009
    Location
    Vancouver, WA, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Braddy,

    This is all very interesting.

    document.lastModified comes from the Last-Modified header sent by the server.

    Unfortunately, JavaScript on different browsers seem to return this value in various ways, for example, if the Last-Modified header is:

    Fri, 09 Jul 2010 17:38:14 GMT

    and the browser is in the Pacific time zone

    document.lastModified is returned by JavaScript as:

    IE8: 07/09/2010 10:38:14
    Firefox 3.6.6: 07/09/2010 10:38:14
    Safari 5.0: Fri, 09 Jul 2010 17:38:14 GMT
    Opera 10.53: Fri, 09 Jul 2010 17:38:14 GMT

    IE8 and Firefox convert it to local time but Safari and Opera do not.

    Using Date(document.lastModified) instead of just document.lastModified seems to force all four browsers (at least the versions tested) to return the date in local time:

    Date(document.lastModified) is returned as:

    IE8: Fri Jul 09 10:38:51 2010
    Firefox 3.6.6: Fri Jul 09 2010 10:39:26 GMT-0700 (Pacific Daylight Time)
    Safari 5.0: Fri Jul 09 2010 10:39:18 GMT-0700 (Pacific Daylight Time)
    Opera 10.53: Fri Jul 09 2010 10:39:02 GMT-0700

    Hope this helps some.

    Robert

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post
    A big thank you to all who replied to this thread, it has given me food for thought.

    Thanks again

    Braddy
    If you are a fool at forty, you will always be a fool

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Brady,

    I tried this and it works on both FF 3.6.6 (both native & using IE Tab & IE 8.0.

    Code:
     <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
          
    
    This is a test of the Last Modified date returned and manipulating it:</p>
         
           <script language="Javascript" type="text/javascript">
           <!--
             document.write("Value returned by document.lastModified: " +document.lastModified)   
            -->  
           </script>
           
           <script language="Javascript" type="text/javascript">
           <!--
             document.write("Reformatted to Euro date: "+ document.lastModified.substr(3,2) + "/" + document.lastModified.substr(0,2) + "/" + document.lastModified.substr(6,4))
            -->  
           </script>
    
          
    
     Test ends here</p>
    
       </body>
    Attached Images Attached Images
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. #7
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post
    HI

    Thanks for all the help on this.

    Regards

    Braddy
    If you are a fool at forty, you will always be a fool

Posting Permissions

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