Why does getDay return incorrect values? (javascript)

前端 未结 1 722
小鲜肉
小鲜肉 2020-12-11 15:48

I tried to get the day of a week with the getDay() function of the Date object in Javascript. In theory it works fine, but sometimes there is a de

相关标签:
1条回答
  • 2020-12-11 16:26

    Because the month number is zero based, not one based.

    new Date("2009","04","30") creates a Date object for the 30th of may, not the 30th of april.

    (The reason why it's zero based is probably historic, i.e. it behaves the same as some method in a different system way back in time...)

    0 讨论(0)
提交回复
热议问题