Minimum and maximum date

I was wondering what is the minimum and maximum date allowed for a Javascript Date object. I found that the minimum date is something like 200000 BC, but I could not get any link about it.

Does anyone know the answer? I just hope this is browser independent.

The answer in "epoch time" (= milliseconds from 1970-01-01 00:00:00 UTC + 00) will be the best.

+111
javascript max datetime
Jul 17 2018-12-17T00:
source share
3 answers

From spec, & sect; 15.9.1.1 :

The Date object contains a number indicating a specific point in time, for a millisecond. This number is called the time value. The time value can also be NaN, indicating that the Date object does not represent a specific point in time.

Time is measured in ECMAScript in milliseconds from January 01, 1970 UTC. In time values, jump seconds are ignored. It is estimated that there are exactly 86.4 million 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 is sufficient to measure time to millisecond accuracy for any moment that is within approximately 285,616 years, both forward and backward, from January 01, 1970 UTC.

The actual time range supported by ECMAScript Date objects is slightly smaller: from exactly 100,000,000 days to 100,000,000 days, measured from midnight at the beginning of January 1, 1970, UTC. This gives a range of 8,640,000,000,000,000 milliseconds on either side of January 01, 1970 UTC.

The exact time of midnight at the beginning of January 1, 1970 UTC is represented by a value of +0.

The third paragraph is the most relevant. Based on this point, we can get the exact early date for each speculator from new Date(-8640000000000000) , which is on Tuesday, April 20, 271 821 BC. E. (BCE = before Common Era , for example, year -271.821).

+151
Jul 17 '12 at 16:10
source share

To increase the TJ response exceeding the min / max values, generates an invalid date.

 let maxDate = new Date(8640000000000000); let minDate = new Date(-8640000000000000); console.log(new Date(maxDate.getTime()).toString()); console.log(new Date(maxDate.getTime() - 1).toString()); console.log(new Date(maxDate.getTime() + 1).toString()); // Invalid Date console.log(new Date(minDate.getTime()).toString()); console.log(new Date(minDate.getTime() + 1).toString()); console.log(new Date(minDate.getTime() - 1).toString()); // Invalid Date 
+36
May 05 '17 at 12:24 a.m.
source share

A bit more comprehensible but less efficient code

 new Date('1970-01-01Z00:00:00:000') //returns Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time) new Date('1970-01-01Z00:00:00:000').getTime() //returns 0 new Date('1970-01-01Z00:00:00:001').getTime() //returns 1 
-3
Jul 30 '18 at 9:57
source share



All Articles