Creating date with numbers (new Date(2012, 03, …) gives wrong month (+1)

前端 未结 1 605
无人及你
无人及你 2020-11-27 08:29

When creating a new Date object using numbers for the parts, the value I get back is exactly one month ahead of the value I put in for \'month\

相关标签:
1条回答
  • 2020-11-27 09:04

    Programmers start counting from 0. So months are represented by 0(Jan)-11(Dec).

    The reason days don't follow this rule is to not confuse authors with 30/31 month differences.

    From MDN:

    month

    Integer value representing the month, beginning with 0 for January to 11 for December.

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