1925年之前的JavaScript日期错误的分钟和秒数[重复]

问题描述 投票:10回答:1

这个问题在这里已有答案:

我有一个应用程序,允许用户选择一些时间段。默认情况下,时隙为空,我的.NET后端具有类型为DateTimeOffset的默认生成值,默认情况下设置为"0001-01-01T00:00:00+00:00"

现在,当我使用此值在前端填充日期时,它会在本地时区生成一个日期,但会有错误的分钟和秒。这只发生在Chrome中。我没有在Edge或Firefox下看到这个。

console.log(new Date("2001-01-01T00:00:00+00:00").toString())
// Mon Jan 01 2001 02:00:00 GMT+0200 (Eastern European Standard Time)
console.log(new Date("1001-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1001 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1801-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1801 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1901-01-01T00:00:00+00:00").toString())
//Tue Jan 01 1901 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1961-01-01T00:00:00+00:00").toString())
//Sun Jan 01 1961 03:00:00 GMT+0300 (Eastern European Standard Time)
console.log(new Date("1921-01-01T00:00:00+00:00").toString())
//Sat Jan 01 1921 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1931-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1931 03:00:00 GMT+0300 (Eastern European Standard Time)
console.log(new Date("1922-01-01T00:00:00+00:00").toString())
//Sun Jan 01 1922 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1923-01-01T00:00:00+00:00").toString())
//Mon Jan 01 1923 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1924-01-01T00:00:00+00:00").toString())
//Tue Jan 01 1924 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1925-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1925 02:00:00 GMT+0200 (Eastern European Standard Time)

正如你所看到的,我玩了约会,看看之前发生了什么日期,但问题可能不是1925年,只是在当前日期之前的某个时间。有谁知道为什么会这样?

截图请求enter image description here

javascript google-chrome date
1个回答
7
投票

在1883年之前,时区没有标准化。如果你每年检查一下,你会注意到1883年被“打破”了额外的分钟,1884年是“罚款”。 Chrome很好地处理了这种转变 - 您会注意到Firefox中不存在“问题”。

new Date("1883-01-01T00:00:00+00:00")
Sun Dec 31 1882 16:07:02 GMT-0752 (Pacific Standard Time)
new Date("1884-01-01T00:00:00+00:00")
Mon Dec 31 1883 16:00:00 GMT-0800 (Pacific Standard Time)

事实上,你可以追溯到1883年11月18日。

new Date("1883-11-18T00:00:00+00:00")
Sat Nov 17 1883 16:07:02 GMT-0752 (Pacific Standard Time)
new Date("1883-11-19T00:00:00+00:00")
Sun Nov 18 1883 16:00:00 GMT-0800 (Pacific Standard Time)

Chrome非常努力地匹配时间,甚至计算2010年埃及斋月的暂停DST。

在这里阅读更多:https://www.huffingtonpost.com/quora/how-when-and-why-were-tim_b_5838042.html

© www.soinside.com 2019 - 2024. All rights reserved.