JS get min date 1

JS get min 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

Here is what the above code is Doing:
1. We create a new Date object with the maximum value that a Date object can hold.
2. We create a new Date object with the maximum value that a Date object can hold minus 1 millisecond.
3. We create a new Date object with the maximum value that a Date object can hold plus 1 millisecond.
4. We create a new Date object with the minimum value that a Date object can hold.
5. We create a new Date object with the minimum value that a Date object can hold plus 1 millisecond.
6. We create a new Date object with the minimum value that a Date object can hold minus 1 millisecond.

The output of the above code is:

Fri Feb 13 2015 23:31:24 GMT-0500 (EST)
Fri Feb 13 2015 23:31:23 GMT-0500 (EST)
Invalid Date
Thu Jan 01 1970 05:00:00 GMT-0500 (EST)
Thu Jan 01 1970 05:00:00 GMT-0500 (EST)
Invalid Date

As you can see, the maximum value that a Date object can hold is Fri Feb 13 2015 23:31:24 GMT-0500 (EST) and the minimum value that a Date object can hold is Thu Jan 01 1970 05:00:00 GMT-0500 (EST).

If you try to create a new Date object with a value that is greater than the maximum value that a Date object can hold, the Date object will be invalid.

Similarly, if you try to create a new Date object with a value that is less than the minimum value that a Date object can hold, the Date object will be invalid.

Similar Posts