What is the maximum and the minimum date that I can use with the
Is it possible to represent ancient historical dates (like
January 1, 2,500 B.C.) or dates that are far into the future (like
October 7, 10,000)?
If these far-from-present dates can’t be represented with the
Date object, how should I represent them?
According to §184.108.40.206 of the ECMA-262 specification,
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.
The actual range of times supported by ECMAScript Date objects is … exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC.
So the earliest date representable with the
Date object is fairly far beyond known human history:
new Date(-8640000000000000).toUTCString() // Tue, 20 Apr 271,822 B.C. 00:00:00 UTC
The latest date is sufficient to last beyond Y10K and even beyond Y100K, but will need to be reworked a few hundred years before Y276K.
new Date(8640000000000000).toUTCString() // Sat, 13 Sep 275,760 00:00:00 UTC
Any date outside of this range will return
new Date(8640000000000001) // Invalid Date new Date(-8640000000000001) // Invalid Date
Date type will be sufficient for measuring time to millisecond precision within approximately 285,616 years before or after January 1, 1970. The dates posted in the question are very comfortably inside of this range.