OStack程序员社区-中国程序员成长平台

标题: javascript - Browsers, time zones, Chrome 67 Error (historic timezone changes) [打印本页]

作者: 菜鸟教程小白    时间: 2022-4-23 21:05
标题: javascript - Browsers, time zones, Chrome 67 Error (historic timezone changes)

I've updated Chrome to 67 version. And I get an error with the date

==============

Microsoft Edge 42.17134.1.0

new Date("1900-01-01T00:00:00").getTimezoneOffset() 

-180

new Date("2018-05-30T00:00:00").getTimezoneOffset()

-180

Microsoft Internet Explorer 11.48.17134.0

new Date("1900-01-01T00:00:00").getTimezoneOffset() 

-180


new Date("2018-05-30T00:00:00").getTimezoneOffset() 

-180

Mozilla Firefox 60.0.1

new Date("1900-01-01T00:00:00").getTimezoneOffset() 

-180

new Date("2018-05-30T00:00:00").getTimezoneOffset() 

-180

Chrome 67.0.3396.62

new Date("1900-01-01T00:00:00").getTimezoneOffset() 

-150

new Date("2018-05-30T00:00:00").getTimezoneOffset()

-180

======================

-150 in Chrome 67...

Another Example (Chrome 67):

new Date("1900-01-01T00:00:00");

Mon Jan 01 1900 00:00:00 GMT+0230 (Moscow Standard Time)

======================

With Chrome 67, time zones began incorrect (+0230, was: +0300)

Please Tell me?

What Can I Do ?

The situation is very important! All code I must to rewrite...

======================



Best Answer-推荐答案


I'm going to assume you're in the Europe/Moscow time zone - that seems likely given the output you've provided.

In 1900, the Europe/Moscow time zone had an offset of +02:30:17, according to the IANA time zone database. Presumably Chrome is rounding down to 02:30 to avoid sub-minute offsets, but it's returning appropriate data as far as I can see. The offset in Russia first became a whole number of hours in 1919, at least according to the IANA database.

Arguably you should be asking why the other browsers are not doing that - but more likely, you should change your code to not ask for time zone information prior to 1970. The IANA database aims to provide accurate data from the Unix epoch onwards; anything earlier is very much "best effort". From the theory file:

Clock transitions before 1970 are recorded for each such location, because most systems support timestamps before 1970 and could misbehave if data entries were omitted for pre-1970 transitions. However, the database is not designed for and does not suffice for applications requiring accurate handling of all past times everywhere, as it would take far too much effort and guesswork to record all details of pre-1970 civil timekeeping. Although some information outside the scope of the database is collected in a file backzone that is distributed along with the database proper, this file is less reliable and does not necessarily follow database guidelines.

In terms of why you're seeing this with Chrome 67 if you weren't seeing it with previous versions of Chrome - I wonder whether Chrome has just started bundling IANA time zone data rather than using the OS data.






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4