SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: strange date

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2003
    Location
    somewhere on the Earth
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    strange date

    assuming today is Aug 3, 2003
    Code:
    today=new Date()
    ncee=new Date("2003,8,3")
    msPerDay=24*60*60*1000
    daysLeft=Math.round((ncee.getTime()-today.getTime())/msPerDay)
    document.write(daysLeft)
    it will return 30 days!

    but

    Code:
    today=new Date()
    ncee=new Date("Aug 3, 2003")
    msPerDay=24*60*60*1000
    daysLeft=Math.round((ncee.getTime()-today.getTime())/msPerDay)
    document.write(daysLeft)
    will just work fine

    Really strange

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's because when instantiating a Date object with the (yyyy, mm, dd) arguments, you must enter the month as a zero-based number. January = 0, February = 1 ... September = 8.

    Here's a good Date reference page
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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