Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the maximum value for Instant#ofEpochSecond(?)

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
like image 883
Jin Kwon Avatar asked Dec 06 '25 07:12

Jin Kwon


1 Answers

You can get the max/min second like this:

import java.time.Instant;


long maxSecond = Instant.MAX.getEpochSecond(); 
long minSecond = Instant.MIN.getEpochSecond();
like image 134
John Avatar answered Dec 08 '25 20:12

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!