I’m having a problem with the Date object in JavaScript. I’ve tested it in Firefox and IE.
The following code shows the problem:
alert(new Date(Date.UTC(2011,6,5,1,0,0,0)).getUTCDay().toString());
I’m expecting 0 since 5 June 2011 is Sunday, but it returns 2 thinking it is Tuesday. Do you know why?
Months start at 0, not 1.
So you’re looking at July, not June. 5th July will be a Tuesday.
(I wrote it out like
6-1rather than just5to make it clear what I’ve changed.)The documentation is your friend. Read it whenever you use a function, especially if you run into trouble.