6

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.

Marc M.
  • 3,631
  • 4
  • 32
  • 53
  • 1
    Is `long` 32-bit or 64-bit (or something else, even)? i.e. what is the value of `Long.MAX_VALUE`? Also, are you assuming the "usual" Jan 1, 1970 00:00:00 UTC as your epoch reference, or something else? – twalberg Nov 22 '13 at 19:54
  • 1
    Regarding terminology, [epoch](https://en.wikipedia.org/wiki/Epoch_%28reference_date%29) means the beginning of time. "The End of Time" might have been a better title for this question. :-) – Basil Bourque Nov 23 '13 at 06:59

3 Answers3

16
System.out.println(new java.util.Date(Long.MAX_VALUE).toGMTString());
// output:  17 Aug 292278994 07:12:55 GMT
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
5

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.

Community
  • 1
  • 1
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
2

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.

Sandman
  • 2,577
  • 2
  • 21
  • 32
  • Okay, good to know. So we got a while. Thanks I was asking because I knew when using a 32-bit Java int to hold seconds since epoch your Integer.MAX_VALUE can only take you to the year 2038. – Marc M. Nov 23 '13 at 00:10