The Mystery Of Javascript getDate vs getMonth Values
Have you wondered why in Javascript, getMonth() returns a number from 0 to 11, whilst getDate() returns a number from 1 to 31?
It turns out this isn't a mistake or an oversight, but by design; while it doesn't explicitly say so in http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf (page 340), getMonth returns a 0-based integer so you can use it easily with an array of month names:
var months = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
var d = new Date();
var monthName = months[d.getMonth()];
But it wouldn't make sense to do so with actual date numbers as there isn't a common scenario to use those along with an array.
Either way, you still have to +1 the month value when you want to represent it numerically, or you have to -1 when you want to use it in conjuction with an array of names, but it's interesting to know why this discrepancy exists.
Lazaro De Almeida said
So I dropped Brendan Eich a tweet asking him the question (for those who don't know he is the creator of JS) and his response was:
@magrangs because that is how java.util.Date did it.