gpt4 book ai didi

javascript - JavaScript 中的 new Date() 中显示的日期不正确

转载 作者:行者123 更新时间:2023-12-04 16:24:13 25 4
gpt4 key购买 nike

enter image description here

这就是我在 chrome 控制台中得到的。我将“2016-09-05”(YYYY-MM-DD) 作为日期传递,它显示的日期是 2016 年 9 月 4 日。

另一个构造函数显示正确的日期

enter image description here

传递逗号分隔需要一些标记化 + 解析 + 使月份零索引,我想避免

最佳答案

如果省略 new Date(string) 中的时间构造函数,假定 UTC 时间。所以显示的值实际上是正确的。使用new Date('2016-09-05 00:00')以本地时间创建日期对象。

关于javascript - JavaScript 中的 new Date() 中显示的日期不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39223481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com