Reputation: 73
Is there a possibility that Date.now() will start returning numbers in scientific notation?
It can possibly be a bug like Y2K. Is it safe to use it? Will it cross the biggest number possible in JavaScript?
Upvotes: 0
Views: 1107
Reputation: 10264
The biggest integer (Number.MAX_SAFE_INTEGER) JavaScript can handle is 2^53 - 1
.
Converting that to years:
console.log(Number.MAX_SAFE_INTEGER / 1000 / 60 / 60 / 24 / 365)
// outputs 285616.41472415626
So the answer is YES, it's safe to use it.
Upvotes: 3
Reputation: 71961
That's not going to be a concern of yours:
Number.MAX_SAFE_INTEGER
to Date
:
Wed 12 Oct 287396
Relative: In 287.396 years
On the other hand
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.
However unrelated, there is the year 2038 problem which might set you off, but as mentioned is not related to JS
The Year 2038 problem (also called Y2038 or Y2k38 or Unix Y2K) relates to representing time in many digital systems as the number of seconds passed since 00:00:00 UTC on 1 January 1970 and storing it as a signed 32-bit integer. Such implementations cannot encode times after 03:14:07 UTC on 19 January 2038. Similar to the Y2K problem, the Year 2038 problem is caused by insufficient capacity used to represent time.
Date is funny :)
Upvotes: 2