admin管理员组文章数量:1336600
I'm reading info on the mix/max values of JavaScript date objects in various implementations.
Mozilla docs say JavaScript supports "-100,000,000 days to +100,000,000 on either side" of the UNIX epoch. If my math is correct, this should be 8.64e15 ms on either side.
Microsoft MSDN says JScript supports "approximately 285,616 years on either side" of the UNIX epoch.
The unit tests for Google v8 indicate +/-1e8 days from epoch.
ECMAScript 5.1 specifies a little more clearly:
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values 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,992 to 9,007,199,254,740,992; 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
I'm curious, does anyone know any implementation which do not actually support this "+/-1e8 days from epoch" range?
I'm reading info on the mix/max values of JavaScript date objects in various implementations.
Mozilla docs say JavaScript supports "-100,000,000 days to +100,000,000 on either side" of the UNIX epoch. If my math is correct, this should be 8.64e15 ms on either side.
Microsoft MSDN says JScript supports "approximately 285,616 years on either side" of the UNIX epoch.
The unit tests for Google v8 indicate +/-1e8 days from epoch.
ECMAScript 5.1 specifies a little more clearly:
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values 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,992 to 9,007,199,254,740,992; 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
I'm curious, does anyone know any implementation which do not actually support this "+/-1e8 days from epoch" range?
Share Improve this question edited Sep 17, 2013 at 16:54 mckamey asked Oct 3, 2011 at 21:32 mckameymckamey 17.5k16 gold badges86 silver badges118 bronze badges 3- 1 It would be very entertaining to learn of the application you're contemplating wherein this detail would be important :-) – Pointy Commented Oct 3, 2011 at 21:38
- 1 He is writing a flux capacitor application. – Kris Krause Commented Oct 3, 2011 at 21:45
- 1 I had this interesting idea after I slipped & hit my head on the edge of the sink. – mckamey Commented Oct 4, 2011 at 0:55
2 Answers
Reset to default 4This works on all major version browsers:
var d = new Date();
d.setTime(8640000000000000);
document.write(d);
Results:
Fri Sep 12 275760 20:00:00 GMT-0400 (Eastern Daylight Time)
This does not work:
d.setTime(8640000000000001);
On IE7/WinXP I get js errors.
I doubt there is such an implementation is use today. Once you support the integer range there's no reason not to support the date range. And that integer range is a side effect of the other requirements of the Number type in js (see 8.5 in the standard, Number is basically IEEE 754). So it's all kind of one package. Meaning, if there was such an implementation, most likely they aren't implementing Number in the correct fashion, which is highly unlikely.
本文标签: datetimeFull range of JavaScript Date objectsStack Overflow
版权声明:本文标题:datetime - Full range of JavaScript Date objects? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742409880a2469572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论