AFAIK java stores dates in long variables as milliseconds. Consequently someday there will be no value (cause long has a maximum) which will correspond to the time of that instant. Do you know when it will happen?
-
8I believe the sun is expected to go nova before then. Sun has already gone nova. – Paul Tomblin Nov 16 '10 at 14:23
-
3Actually, I have that wrong - Java Date has 292 million years, but according to http://www.space.com/scienceastronomy/solarsystem/death_of_earth_000224.html the earth has 500 million years. – Paul Tomblin Nov 16 '10 at 14:30
-
Related: http://stackoverflow.com/questions/2978452/when-will-system-currenttimemillis-overflow – BalusC Nov 16 '10 at 23:35
2 Answers
It's easy enough to find out:
public class Test {
public static void main(String[] args) {
System.out.println(new java.util.Date(Long.MAX_VALUE));
}
}
Gives output (on my box):
Sun Aug 17 07:12:55 GMT 292278994
You may need to subtract a bit from Long.MAX_VALUE
to cope with your time zone overflowing the range of long, but it will give a reasonable ballpark :)

- 1,421,763
- 867
- 9,128
- 9,194
-
-
4No, no, no... it breaks one millisecond AFTER the time posted. If it was displaying milliseconds, that is. – Powerlord Nov 16 '10 at 16:23
According to the current leap-year regulations the average number of days per year will be
365 + 1/4 − 1/100 + 1/400 = 365.2425 days per year
This means that we, in average, have 31556952000 milliseconds per year.
The long-value represents the number of milliseconds since the Epoch (1st of January, 1970) and the maximum number represented by a Java long is 263 − 1, so the following calculation
1970 + (263 − 1) / 31556952000
reveals that this representation will overflow year 292278994.
This can, as Jon Skeet points out, be confirmed by
-> System.out.println(new Date(Long.MAX_VALUE));
Sun Aug 17 08:12:55 CET 292278994
-
2With such large numbers being used as dates, leap seconds and tidal acceleration probably need to be factored in too. – Qwerky Nov 16 '10 at 14:35
-
2@Qwerky, yeah, I thought about that too, and search for astronomical measurements of the number of milliseconds of a year, but then it struck me that the question was about the java date-implementation, and this does most likely *not* take tidal acceleration etc into account :-) – aioobe Nov 16 '10 at 14:37