在Chrome 67上打破了新的日期() [英] new Date() broken on Chrome 67

查看:60
本文介绍了在Chrome 67上打破了新的日期()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动Chrome 67(完整版本为67.0.3396.87),我遇到了创建新Date对象的奇怪行为。最小的可重现案例如下:

Starting Chrome 67 (full version is 67.0.3396.87), I am experiencing weird behaviour with creation of a new Date object. Smallest reproducible case, goes something like:

    <html>
    <body>    
    <script>    alert(new Date(-62135596800000));        </script>
    </body>
    </html>

在Firefox 60.0.2上,警告信息为:

On Firefox 60.0.2 the alert message is:

Mon Jan 01 0001 00:00:00 GMT + 0000(GMT标准时间)

开Internet Explorer 11和Edge 41.16299.461.0,警报消息与Firefox相同:

On Internet Explorer 11 and Edge 41.16299.461.0, the alert message is same as Firefox:

Mon Jan 01 0001 00:00:00 GMT+0000 (GMT Standard Time)

但是,在Chrome 67上我看到:

However, on Chrome 67 I see:

Sun Dec 31 0000 23:58:45 GMT-0001 (Greenwich Mean Time)

编辑 JsFiddle

Edit2 原来这与微软的图书馆无关。

Edit2 Turns out it's nothing to do with Microsoft's library.

推荐答案

根据对该错误报告的响应,我认为这实际上是由于Chrome可能包含IANA时区信息。 浏览器,时区,Chrome 67错误

Depending on the response to that bug report, I think this is actually due to Chrome possibly including IANA timezone information. Browsers, time zones, Chrome 67 Error

例如,当我运行那个小提琴时,我得到 Sun Dec 31 0000 18:09:24 GMT-0550(中央标准时间)对应到IANA条目 Zone America / Chicago -5:50:36 - LMT 1883 Nov 18 12:09:24

For example, when I run that fiddle, I get Sun Dec 31 0000 18:09:24 GMT-0550 (Central Standard Time) which corresponds to the IANA entry Zone America/Chicago -5:50:36 - LMT 1883 Nov 18 12:09:24.

所以这是一个功能而不是我认为的错误。他们使用更准确的历史时间偏移而不是历史日期的当前日期偏移。

So this is a "feature" not a bug I think. They are using the more "accurate" historical time offsets instead of current day time offsets for historical dates.

您可以在此处查看数据: https://github.com/eggert/tz 只需查找相应的世界位置文件,并尝试避免所有注释掉的行,除非你对你所在时区的历史感到好奇。

You can view the data here : https://github.com/eggert/tz just look for your appropriate world location file and try and avoid all the commented out lines unless you are morbidly curious about the history of your time zones.

你可以做些什么来修复它所以显示或多或少正确显示就是打电话给 .toUTCString()日期对象上将强制它进入UTC时间并显示 Mon,01 Jan 0001 00:00:00 GMT 正如@Pointy在初始问题的评论中指出的那样。

What you can do to "fix" it so it display more or less correctly is to call .toUTCString() on the Date object which will force it to UTC time and display Mon, 01 Jan 0001 00:00:00 GMT as @Pointy pointed out in the comments on the initial question.

这篇关于在Chrome 67上打破了新的日期()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆