1

The javascript date method now() returns number of milliseconds since 1970/01/01. It is an integer number. This number keeps on increasing as time moves on. What will be the maximum or end value it could reach? How many centuries or millenniums it could take?

I am sure this ever increasing integer cannot grow beyond a very high integer? What is that limit?

Will this method Date.now() stop working once reaching that day in future?

Vijey
  • 6,536
  • 7
  • 43
  • 50
  • 1
    Well the largest representable integer in a JavaScript number is given by `Number.MAX_SAFE_INTEGER` – Pointy Apr 15 '19 at 16:03
  • Duplicate of [Minimum and maximum date](https://stackoverflow.com/questions/11526504/minimum-and-maximum-date). – Rich Apr 15 '19 at 16:22

1 Answers1

2

Using Number.MAX_SAFE_INTEGER, which is 2^53 - 1:

9007199254740991/1000 ms per second/60 seconds per minute/60 minutes per hour/24 hours per day/365 days per year = 285616.414724

Thus, it should stop working in 285,616 years since 1970

Ben Gubler
  • 1,393
  • 3
  • 18
  • 32
  • 4
    Not quite. `new Date( Number.MAX_INTEGER-1 );` returns an Invalid Date. The actual maximum number of ms is actually about 400 trillion less than you listed. See the [ECMAScript spec](http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.1). The highest possible date is `Sat, 13 Sep 275760 00:00:00 GMT`. – Rich Apr 15 '19 at 16:32