admin管理员组文章数量:1426066
Of course it took another 200,000 years for that to happen. But will the Javascript dating system error after the value of Date.now()
exceeds the value of Number.MAX_SAFE_INTEGER
? What consequences will occur?
Maybe this question looks strange and useless. But can anyone answer my curiosity and also other people who might have the same question.
Of course it took another 200,000 years for that to happen. But will the Javascript dating system error after the value of Date.now()
exceeds the value of Number.MAX_SAFE_INTEGER
? What consequences will occur?
Maybe this question looks strange and useless. But can anyone answer my curiosity and also other people who might have the same question.
Share Improve this question asked May 21, 2020 at 23:04 Laode Muhammad Al FatihLaode Muhammad Al Fatih 4,6401 gold badge22 silver badges38 bronze badges 4-
2
Epoch time returned from
Date.now
simply counts the number of seconds since Jan 1, 1970. Have you ever wondered how to represent dates before that time? Forget about 200,000 years into the future, that's just 50 years ago! Using an integer to represent a date is convenient, but it's not an implementation requirement. You have a long time to e up with another Date standard that supports a wider range of dates. – Mulan Commented May 21, 2020 at 23:09 - 7 I've e from the year 202020 - javascript is no longer used, since we don't have web pages any more, we've evolved beyond such primitive forms of information transfer - all information is passed using odours – Jaromanda X Commented May 21, 2020 at 23:09
- @JaromandaX Hahahaha – Squidward Tentacles Commented May 21, 2020 at 23:14
- The puter explodes, be careful. – virtual_Black_Whale Commented May 23, 2020 at 0:35
1 Answer
Reset to default 9What you describe is ruled out by ECMA-262. The maximum value that can be returned by Date.now is ±8.64e15, which is well within the range of integers safely supported by ECMAScript.
The maximum value can represent 1e9 days either side of the epoch (1 Jan 1970) so a range of approximately ±273,790 years. I think there will be time to address the issue before it arises.
Constructing a date for the maximum value returns a date for +275760-09-13T00:00:00.000Z. Adding one millisecond to the time value returns an invalid date:
// Max value returnable by Date.now
let maxDateNowValue = 8.64e15;
console.log(new Date(maxDateNowValue).toISOString()); // +275760-09-13T00:00:00.000Z
// Max value plus 1 millisecond
let plusOneMS = maxDateNowValue + 1;
console.log(new Date(plusOneMS).toString()); // Invalid Date
本文标签: javascriptWhat happens if Datenow () is greater than NumberMAXSAFEINTEGERStack Overflow
版权声明:本文标题:javascript - What happens if Date.now () is greater than Number.MAX_SAFE_INTEGER? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745392695a2656671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论