SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Brazil
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bug in Date Object

    Guys,

    Im trying to create a simple calendar, but Ive found that the date object has a bug, at least with Brazilian GMT time. The object considers month 1 (February) as March. Can someone give a help on how to go over this?

    Thanks!

    var d = new Date()
    d.setMonth(1)
    document.write(d);

    ----> Fri Mar 02 2007 14:03:21 GMT-0300 (Hora oficial do Brasil)

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The month object is 0 based, 0 is January, 11 is December.
    use 0 to setMonth or getMonth.

    But note, you can parse a string to a date in a conventional way:
    new Date(2007,0,1) is the same as new Date('1/1/2007')

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    February is indeed month 1.

    HOWEVER, February has 28 days, and we are at the 30th of January. So if you add a month to 30 January you get.......2nd of March.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You prefer february 30?

    January 31 + 1 month= March 3
    January 31 + 2 months= March 31
    January 31 + 3 months= May 1
    January 31 + 4 months= May 31
    January 31 + 5 months= July 1
    January 31 + 6 months= July 31
    January 31 + 7 months= August 31
    January 31 + 8 months= October 1
    January 31 + 9 months= October 31
    January 31 + 10 months= December 1
    January 31 + 11 months= December 31
    January 31 + 12 months= January 31 (2008)


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
  •