Frage

If stored in milliseconds, what is the human readable date for the value dateTime? Epoch is Thursday, 1 January 1970, and I mean long as in Java long.

long dateTime = Long.MAX_VALUE; 

All the online tools seem to crash when I give them a value this large.

War es hilfreich?

Lösung

System.out.println(new java.util.Date(Long.MAX_VALUE).toGMTString());
// output:  17 Aug 292278994 07:12:55 GMT

Andere Tipps

I took Matt Johnson's correct answer and tried it in Joda-Time 2.3 on Java 7 on OS X (Mountain Lion). I got the same result.

// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.

System.out.println( "Long.MAX_VALUE: " + Long.MAX_VALUE );
org.joda.time.DateTime endOfTime = new org.joda.time.DateTime( Long.MAX_VALUE );
org.joda.time.DateTime endOfTimeUtc = endOfTime.toDateTime( org.joda.time.DateTimeZone.UTC );
System.out.println( "endOfTimeUtc: " + endOfTimeUtc );

When run…

Long.MAX_VALUE: 9223372036854775807
endOfTimeUtc: 292278994-08-17T07:12:55.807Z

So we've got over a quarter billion years to go.

If i check the current time in millis i get something like this: 1385148606519. If you multiply by 1000 you get 1385148606519000, which is Wed Aug 12 45863 2:48:39 PM UTC. If you then change the first digit from 1 to 8 you get 8385148606519000 which is Thu Oct 12 267684 3:15:19 AM UTC. Through such progressive changes i can get to the most distant date which won't crash Javascript: 8640000007200000 which is Sat Sep 13 275760 3:00:00 AM. I don't know whether there's a reliable way to actually calculate the exact number which you want... May i ask what you need that for? :)

For simplicity you can try to consider the no. of millis in a year with 365 days: 31556952000. So ignoring for a moment any kind of leap second or year we can divide MAX_VALUE by that 9223372036854775807 / 31556952000 = 292277024.627 years from 1970 which probably means some year around 292278994.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top