How to get the minimum and maximum date

How to get the smallest and largest date. I see that the smallest number can be obtained as follows:

Number.MIN_VALUE 

Date does not have this. Is there a way to find the smallest and largest date

+10
javascript momentjs
Nov 23 '14 at 19:13
source share
1 answer

Date does not have this

Actually, this happens, but only indirectly. According to the specification, the value of <milliseconds Date a milliseconds-after-the-Epoch object can only be in the range of -8640000000000000 to 8640000000000000.

So, the minimum date is new Date(-8640000000000000) (Tue, April 20 -271821 00:00:00 GMT), and the maximum date is new Date(8640000000000000) (Sat, Sep 13, 275760 00:00:00 GMT).

If you want, you can put them in the Date function as properties:

 Date.MIN_VALUE = new Date(-8640000000000000); Date.MAX_VALUE = new Date(8640000000000000); 

... but since Date instances are changing, I probably won't, because it is too easy to accidentally change one of them. An alternative would be to do this:

 Object.defineProperties(Date, { MIN_VALUE: { value: -8640000000000000 // A number, not a date }, MAX_VALUE: { value: 8640000000000000 } }); 

Defines properties on Date that cannot be changed, which have a minimum / maximum numeric value for dates. (On a JavaScript engine that supports ES5.)

+20
Nov 23 '14 at 19:17
source share



All Articles