gpt4 book ai didi

javascript - Date.Parse() 的时区问题

转载 作者:行者123 更新时间:2023-11-28 13:44:23 24 4
gpt4 key购买 nike

我的脚本中有以下代码:

Date.parse('10/01/2010 01:01:01')

运行脚本后得到的结果是这样的:

September 30, 2010 22:01:01

这可能是 Date.Parse() 的问题还是我做错了什么?

最佳答案

这不是问题:它是 feature :

The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. The local time zone is used to interpret arguments that do not contain time zone information. [...] If you do not specify a time zone, the local time zone is assumed.

...所以两者之间有区别:

Date.parse("Thu, 01 Jan 1970 00:00:00");

// ... returns 14400000 in timezone GMT-0400, and other values in other
// timezones, since there is no time zone specifier in the argument.

...和...

Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0400");
// ... returns 14400000 no matter the local time zone.

关于javascript - Date.Parse() 的时区问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15478615/

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