I just found that the Instant#ofEpochSecond(epochSecond)
has minimum/maximum values.
Here comes the source codes.
// Instant.java
/**
* The minimum supported epoch second.
*/
private static final long MIN_SECOND = -31557014167219200L;
/**
* The maximum supported epoch second.
*/
private static final long MAX_SECOND = 31556889864403199L; // << I WANT THIS VALUE!
How can I get the MAX_SECOND
programmatically?
I tried to figure out with Range
,
final var range = ChronoField.INSTANT_SECONDS.range();
log.debug(" minimum: {}", range.getMinimum());
log.debug(" largestMinimum: {}", range.getLargestMinimum());
log.debug(" maximum: {}", range.getMaximum());
log.debug("smallestMaximum: {}", range.getSmallestMaximum());
and has no luck.
03:53:36.120 [ main] DEBUG - minimum: -9223372036854775808
03:53:36.122 [ main] DEBUG - largestMinimum: -9223372036854775808
03:53:36.122 [ main] DEBUG - maximum: 9223372036854775807
03:53:36.122 [ main] DEBUG - smallestMaximum: 9223372036854775807
You can get the max/min second like this:
import java.time.Instant;
long maxSecond = Instant.MAX.getEpochSecond();
long minSecond = Instant.MIN.getEpochSecond();