What date range is allowed in Javascript?

What is the maximum and minimum date that I can use with an object Datein Javascript?

Is it possible to imagine ancient historical dates (for example January 1, 2,500 B.C.) or dates that are far from the future (for example October 7, 10,000)?

If these distant dates cannot be presented to the object Date, how should I represent them?

+5
source share
1 answer

According to §15.9.1.1 of the ECMA-262 specification ,

ECMAScript 01 1970 . UTC.
...
, ECMAScript Date, ... -100 000 000 100 000 000 , 01 1970 UTC.. 8 640 000 000 000 000 000 1 1970 UTC.

, , Date, :

new Date(-8640000000000000).toUTCString()
// Tue, 20 Apr 271,822 B.C. 00:00:00 UTC

, Y10K Y100K, Y276K.

new Date(8640000000000000).toUTCString()
// Sat, 13 Sep 275,760 00:00:00 UTC

Invalid Date.

new Date(8640000000000001)   // Invalid Date
new Date(-8640000000000001)  // Invalid Date

, JavaScript Date 285,616 1 1970 . , , .

+12

All Articles