Incorrect date shown in new Date() in JavaScript

前端 未结 3 394
不思量自难忘°
不思量自难忘° 2020-11-28 14:55

This is what I get in chrome console. I pass \"2016-09-05\"(YYYY-MM-DD) as the date and it shows me Sept 4,2016 as the date.

Another constructor shows the

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 15:03

    If you omit the time in the new Date(string) constructor, UTC time is assumed. So the displayed value is actually correct. Use new Date('2016-09-05 00:00') to create the date object in local time.

提交回复
热议问题