+ 5
Javascript Month Index
I'm so confuse with this: Date(2017, 0, 0).getDate() // 31 Date(2017,1,0).getDate() // 31 ???? Date(2017,2,0).getDate() // 28 ???? Someone please explain.
3 Respostas
+ 5
From what I can see, the Date() constructor returns 31 when initialized with invalid arguments. However, if it can resolve the arguments for year and month, the getDate() method will return the number of days in that month.
It also appears that the parameters are not using zero based indexes to specify month and day.
Therefore, any lines specifying 0 for month will yield 31.
The lines that specify 1 or 2 for month and 0 for days yields the number of days in January and February, respectively.
+ 3
Thanks for that David. Sam, JS Month is 0-based, but thanks anyway :)
0
JavaScript oddly indexes months starting at 1. So the second option is January and the third is Feb