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

后端 未结 8 1145
生来不讨喜
生来不讨喜 2020-11-22 15:31

When initializing a new Date object in JavaScript using the below call, I found out that the month argument counts starting from zero.

new Date(         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 15:50

    Its like this in java too.. Probably to convert int to string (0 - jan,, 1-feb), they coded this way.. because they might have an array of string (indexed from 0) of month names and these month numbers if they start from 0, it'll be lot easier to map to the month strings..

提交回复
热议问题