Java scentific date hanlding

My question is how should a Date be handled when we want to store dates since the birth of earth until end of earth (expected to be at 100000000000000000000-12-31 23:59:00.0000 +1 ).

I am sure some scientists have libraries for Dates like these. Since Joda-Time is also using a long for internal storage it is out of scope. Developing a calender from scratch could be difficult since we have to handle all the special cases like switching from julian to gregorian calendar and leap years/seconds ...

Jon Skeet
people
quotationmark

JSR-310 - the new date/time API in Java 8 - handles this already. From the Instant docs:

For practicality, the instant is stored with some constraints. The measurable time-line is restricted to the number of seconds that can be held in a long. This is greater than the current estimated age of the universe. The instant is stored to nanosecond resolution.

There is a backport to Java 7, if you can't wait for Java 8 to come out :)

However, JSR-310 may not handle leap seconds in the way that you want it to. Basically it tries (entirely reasonably) to remove leap seconds from the system, by insisting that any clocks provided perform smearing. (So the leap second isn't represented in the data model.) You'll need to be careful around that. Of course, dates in the far future make leap second calculations impossible and almost certainly insignificant anyway :)

EDIT: As noted in the answer below, the quote above is effectively a spec error, and Instant will "only" support year values up to a billion.

people

See more on this question at Stackoverflow