Agnel Kurian Agnel Kurian - 3 months ago 26
Javascript Question

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

When initializing a new

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?


It's an old (probably unfortunate, probably dying) tradition in the programming world, see the old standard (POSIX) localtime C function