57
votes

using Mozilla Firefox Firebug:

var myDate = new Date(2012, 9, 23, 0,0,0,0);
myDate;

Date {Tue Oct 23 2012 00:00:00 GMT-0400 (Eastern Daylight Time)}

Why does javascript create the date with the wrong month?

2
JavaScript months are zero indexed... finds the dupe link. - Matt
@Matt: give me couple of minutes to collect some rep points ;-) - zerkms
Eugh, I can't believe I can't find one. Google is failing me. - Matt
@Matt: "site:stackoverflow.com date javascript month zero indexed" ? stackoverflow.com/questions/7834266/… - zerkms

2 Answers

98
votes

No, javascript's Date months start with 0, so 9 is a 10th month and it is October

Reference:

new Date(year, month [, day, hour, minute, second, millisecond]);

[...]

month Integer value representing the month, beginning with 0 for January to 11 for December.

9
votes

In the javascript world months begin with zero! kind of weird to me. Anyhow, 9 is NOT September, but rather 9 is October.