JavaScript的Date对象易受Y2038问题的影响? [英] Is JavaScript's Date object susceptible to the Y2038 problem?
问题描述
Mozilla文档说,一年可以设置为9999,但是我不知道这是否在所有JavaScript实现中都是一致的,或者这是对规范规定的准确描述。
我会认为文档中的措辞,似乎是使用64位数字存储时间或以ISO日期格式存储实际数据。
有人知道浏览器是如何实现的?
不是 - 根据 ECMAScript规范 seciont 15.9.1.1:
时间以ECMAScript为单位,自1970年1月1日以来以毫秒为单位。飞跃秒将被忽略。假设每天正好有86,400,000毫秒。 ECMAScript数值可以表示从-9,007,199,254,740,991到9,007,199,254,740,991的所有整数;这个范围足以在从1970年1月1日UTC UTC前进或后退的大约285,616年内的任何瞬间测量时间到毫秒的精度。
ECMAScript支持的时间Date对象稍微小一些,相对于1970年01月01日01时开始的午夜来说,正好在100亿天至100,000,000天之间。
这给出了一个范围从1月01日的任一侧的8,640,000,000,000,000毫秒,
1970 UTC。 1970年1月1日开始的午夜的确切时刻由值+0表示。
Assuming a 32-bit OS/Browser, could a Date object created in JavaScript rollover to 1970 if I set a date beyond 2038?
The Mozilla documentation says a year can be set to 9999, however I don't know if this is consistent across all JavaScript implementations, or if this is an accurate description of what the specification dictates.
I would think given the wording in the documentation, it seems like it's either using a 64-bit number for storing the time or storing the actual data in ISO date format.
Does anyone know how browsers implement this?
It shouldn't be - according to the ECMAScript specification seciont 15.9.1.1:
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. Leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript number values can represent all integers from –9,007,199,254,740,991 to 9,007,199,254,740,991; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.
The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC.
This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC. The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.
这篇关于JavaScript的Date对象易受Y2038问题的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!