最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

datetime - Full range of JavaScript Date objects? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 4

This 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.

发布评论

评论列表(0)

  1. 暂无评论