(new Date('2012-12-01')).getMonth() === 10?

后端 未结 3 1205
梦毁少年i
梦毁少年i 2021-01-18 08:35

(new Date(\'2012-12-01\')).getMonth() is 10 instead of 11 (getMonth is 0-indexed). I\'ve tested on Firefox, Chrome, and N

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 09:00

    The error is arising from prefixing the day 01 with 0. Not sure WHY this is, but if you remove the zero before the 1, it gives you the right month (11).

    Also, it starts giving the wrong month at October if that means anything.

    Short term fix, use 1 instead of 01.

提交回复
热议问题