Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to set date as infinite in form of timestamp

I want to set the date as an infinite date in form of timestamp? There are people saying we can use "0" and some are saying set big value like this 60*60*24*100. And I do not want to do this. Is there any suitable way of handling this?

like image 586
Dinnu Buddy Avatar asked Mar 19 '15 10:03

Dinnu Buddy


People also ask

How do you format a date time stamp?

In this example, the format of yyyy/MM/dd HH:mm:ss was matched and highlighted in green. This was the first format provided so it returns as 1(format: yyyy/MM/dd HH:mm:ss locator: \[time=(. *?) \]) The Effective message time would be 2017-01-15 02:12.000 +0000.

What is Max date in Javascript?

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.


1 Answers

0 and 60*60*24*100 are bad choices because they are small values (in the first few hours of 1st January 1970).

If you need to deal with the timestamps as a number only, use Infinity. It has the properties I assume you need:

Infinity > Date.now()
// true

Infinity > 60*60*24*100
// true

Infinity > Number.MAX_VALUE
// true

However, it won't work if you need to convert to Date:

new Date(Infinity)
// Invalid Date

If you also need to construct a Date for your timestamp, the largest possible timestamp is 8640000000000000 - see Minimum and maximum date.

var MAX_TIMESTAMP = 8640000000000000;

new Date(MAX_TIMESTAMP)
// Sat Sep 13 275760 01:00:00 GMT+0100 (BST)

new Date(MAX_TIMESTAMP + 1)
// Invalid Date
like image 108
joews Avatar answered Oct 23 '22 07:10

joews