Browser Compatibility in TimeStamp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajit09
    Contributor
    • Dec 2006
    • 296

    #1

    Browser Compatibility in TimeStamp

    Hi


    Code:
    <script type="text/javascript">
    
    var d = new Date();
    var timeStamp = String(d.getFullYear())+String(d.getMonth()+1)+String(d.getDate())+String(d.getHours())+String(d.getMinutes())+String(d.getSeconds());
    document.write(timeStamp);
    
    </script>
    Is the above code browser compatible ?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Do you mean cross-browser compatible? It works in Firefox.

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      If you do not pad the months,days,hou rs, minutes and seconds with leading 0's (if they are single digits) you won't be able to make sense of the time stamp.

      It would be most portable between browsers if you saved just new Date().getTime( ). This returns the milliseconds since January 1, 1970, according to the computer's clock.
      You can reconstitute a Date object anytime from its milliseconds time stamp.

      Comment

      Working...