gpt4 book ai didi

javascript - 为什么 new Date(1970, 0 ,1).getFullYear() 返回 1969?

转载 作者:数据小太阳 更新时间:2023-10-29 05:15:27 25 4
gpt4 key购买 nike

有人可以解释为什么 new Date(1970, 0 ,1).getFullYear() 返回 1969 而不是 1970 吗?

result.textContent = new Date(1970, 0, 1).getFullYear();
<div id=result></div>


归档的 Firefox 错误:https://bugzilla.mozilla.org/show_bug.cgi?id=1093130

最佳答案

看起来很像 Firefox 的 SpiderMonkey 引擎中的时区错误(很可能在它使用的某些库中);在我的实验中,它只影响 *nix 操作系统,不影响 Windows。 (请参阅下文了解时区的原因。)它正在返回

Wed Dec 31 1969 23:00:00 GMT+0000 (BST)

...when of course, we (@wilsonpage, myself, and millions others on UK time) aren't on British Summer Time anymore (and when we are on summer time, it's GMT+0100, not GMT-0100, so it wouldn't make sense for local time to be behind UTC in any case). (Side note: Chrome also shows "BST", but it has the correct date/time.) (Note for Americans: You're used to "xST" meaning "x standard time" [as opposed to "x daylight time"], but here BST stands for "British Summer Time" — e.g., daylight savings time. When we're not on summer time, we're in GMT.)

I see this behavior in Firefox 30 on Linux Mint 16 (apparently the latest in the packages system) and Firefox 33 on that same system (just downloaded and installed from Mozilla directly); I do not see it on Firefox 33 on Windows 8.1.

@wilsonpage has confirmed that he's using OS X and that he's seeing the same time I am (including the "BST" part).

result.textContent = new Date(1970, 0, 1).toString();
<div id=result></div>


时区进入其中(显然会触发错误)的原因是您为该版本的 Date constructor 赋予的值被解释为 UTC,但是 getFullYear返回其在本地时间的值。

关于javascript - 为什么 new Date(1970, 0 ,1).getFullYear() 返回 1969?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26717400/

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