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

后端 未结 5 477
鱼传尺愫
鱼传尺愫 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:17

    It's because today is July 31. Grant explained the problem. Here's what I believe is a simpler solution. Initialize your date on Jan 1.

    var date = new Date(2009,0,1,0,0,0);
    

提交回复
热议问题