我刚刚发现
Instant#ofEpochSecond(epochSecond)
有最小值/最大值。
源代码来了。
// 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!
如何以编程方式获取
MAX_SECOND
?
我试图用
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());
但没有运气。
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
您可以像这样获得最大/最小秒数:
long maxSecond = Instant.MAX.getEpochSecond();
long minSecond = Instant.MIN.getEpochSecond();