the thing about months
In a browser JS console or Node terminal session, enter the following:
var x = new Date(2017,1,1);The expectation would be this would create a new Date object representing Jan. 1, 2017.
But what really happens?
console.log(x);
// 2017-02-01T06:00:00.000ZHuh? We put in Jan 1st and got Feb 1st? WTF…?
Turns out that months are zero-indexed so January is 0 and Dec. is 11.
var xy = new Date(2017,0,1);
console.log(xy);
// 2017-01-01T06:00:00.000ZHere’s a Stack Overflow post explaining the lineage of this implementation. The twitter posts from Brendan Eich are especially interesting.