I’m guessing I’m just mixing up the parameters, but I’ve checked like 100 times.
If I do this:
console.log(new Date(2012, 12, 14, 0, 26, 15, 0));
I get:
Mon Jan 14 2013 00:26:15 GMT+0100 (CET)
But what I’m expecting, is:
Fri Dec 14 2012 00:26:15 GMT+0100 (CET)
Why am I getting this result? I thought the format for the Date-constructor was year, month, day, hour, minute, second, millisecond.
Anybody have an idea what I am missing here?
Javascript month numbers are 0-based. 0=January, 11=December.
So what you want is this:
Yes, this is vaguely ridiculous. The logic behind it is this: you usually want to display month names, and the logical way to get them is to store the names as an array indexed by the month number. Array indices are 0-based. Therefore, the month number should be 0-based.
Decades of programmer annoyance and surprise because someone couldn’t be arsed to subtract 1, or waste an element of a 13-pointer array, or something.
(This is the same logic behind the fact that weekdays are numbered from 0=Sunday to 6=Saturday. That worked out since it is the same modulo 7 as the ISO standard of 1=Monday to 7=Sunday. The differing European/American calendar conventions and 1-vs-0-based counting standards cancelled each other out… :))