www.webdeveloper.com
Results 1 to 3 of 3

Thread: getTime() queer behaviour

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Question getTime() queer behaviour

    My date ordering using getTime() method sometimes doesn't work well, so I looked for an error and this is what I found:

    new Date(2011, 1, 31, 9, 43, 0, 0).getTime() returns 1299141780000
    new Date(2011, 2, 1, 14, 41, 0, 0).getTime() returns 1298986860000

    This is obviously wrong. 1/2 is day after 31/1, but 31/1 gets a higher time stamp.

    PHP function date("r", 1299141780000 * 0.001) returns "Thu, 03 Mar 2011 09:43:00 +0100" so here is problem. Time stamp for 31/1 gains 3 days. It looks like a serious JavaScript bug. Did someone solve it?

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    javascript months are zero based- january is 0, not 1

    your first date sets february 31, 2011, and March 3 is as close as you can get to the 31st day of february

    You are comparing march 3 in the first expression to march 2 in the second, the calculation is correct.

    Next year (leap year) february 31 will be march 2...
    Last edited by mrhoo; 02-01-2011 at 09:27 AM.

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Yes, that's it. Thank you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles