Alex Rivera | Logout

Why does the month argument range from 0 to 11 in JavaScript's Date constructor?

Asked 2010-03-31T11:34:35.007
273

When initializing a new Date object in JavaScript using the below call, I found out that the month argument counts starting from zero.

new Date(2010, 3, 1);  // that's the 1st April 2010!

Why does the month argument start from 0? On the other hand, the day of the month argument (last one) is a number from 1 to 31. Are there good reasons for this?

Edit
Report

2 Answers

35

Everything but the day of the month is 0 based, see here for a full list including ranges :)

It's actually the 1 based days that are the oddballs here...oddly enough. Why was this was done? I don't know...but probably happened the same meeting they got plastered and decided semicolons were optional.

answered 2010-03-31T11:39:14.617
6

There are always 12 months in a year, so early C implementations might have used a static fixed-width array with indexes 0..11.

answered 2010-03-31T11:38:27.400

Your Answer