Javascript date parsing bug - fails for dates in June (??)

后端 未结 5 463
鱼传尺愫
鱼传尺愫 2020-12-18 04:28

I have some javascript which parses an ISO-8601 date. For some reason, it is failing for dates in June. But dates in July and May work fine, which doesn\'t make sense to m

5条回答
  •  时光取名叫无心
    2020-12-18 05:12

    It's the order in which you are changing the date. The date starts out as July 31, so the set of the month fails because there is no 31 in June. (Actually it is rolling over to jul-1.)

    After setting the full year, add this:

    date.setYUTCDate(1);
    

    It makes it the first of the month wherein every month is valid.

提交回复
热议问题