Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the JavaScript Date Range

What is the JavaScript year Range in Date() object

i know in MS SQL year date range is for datetime data type is from 1753-01-01 through 9999-12-31

and even in JavaScript month range is 0- 11 any thing else will be invalid date

i was testing this and here is some of the results :

new Date(99999,1,1) ; //is valid 

But

new Date(1000000,1,1); // invalid 

that means there is a year range right any body knows what is it and why this exact range ?

like image 349
Mina Gabriel Avatar asked Apr 27 '26 09:04

Mina Gabriel


1 Answers

From the docs:

Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It is assumed that there are exactly 86,400,000 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 suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.

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. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC

So if I say like:

var d = new Date();
d.setTime(8640000000000000);
document.write(d);

Then it would output as:

Fri Sep 12 275760 20:00:00 GMT-0400 (Eastern Daylight Time)

But d.setTime(8640000000000001);

will not work

like image 117
Rahul Tripathi Avatar answered Apr 28 '26 22:04

Rahul Tripathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!