Best way to get maximum Date value in java?

Viewed 95763

I'm writing a bit of logic that requires treating null dates as meaning forever in the future (the date in question is an expiration date, which may or may not exist). Instead of putting in special cases for a null date throughout the code, I want to just convert null into the maximum possible Date. I don't see any obvious ways to get such a value without hard coding it. What's the best way to get the maximum value of whatever Date implementation is being used?

9 Answers

From Java SE 8 you could use:

LocalDate.MAX

I like Instant.MAX because it is more likely to be supported in the future than Long.MAX_VALUE.

Note that as of today, though, Instant.MAX.toEpochMilli() throws an overflow error.

Related