Class Instants


  • public class Instants
    extends java.lang.Object
    Works with Instants.
    Since:
    3.21.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long toEpochMillis​(java.time.Instant instant)
      Converts an Instant to milliseconds bound to a long without throwing ArithmeticException.
      static java.time.Instant toInstant​(java.time.Instant instant)
      Returns the given non-null instant, or Instant.EPOCH if null.
      static java.time.Instant toInstant​(java.time.Instant instant, java.time.Instant defaultInstant)
      Returns the given non-null instant, or defaultInstant if instant is null.
      static long toMillisSince​(java.time.Instant instant)
      Converts an Instant to milliseconds since that Instant bound to a long without throwing ArithmeticException.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toEpochMillis

        public static long toEpochMillis​(java.time.Instant instant)
        Converts an Instant to milliseconds bound to a long without throwing ArithmeticException.
        • If the duration milliseconds are greater than Long.MAX_VALUE, then return Long.MAX_VALUE.
        • If the duration milliseconds are lesser than Long.MIN_VALUE, then return Long.MIN_VALUE.
        • If the instant is null, treat it as Instant.EPOCH.
        Parameters:
        instant - The instant to convert, not null.
        Returns:
        long The given Instant in milliseconds.
        See Also:
        Instant.toEpochMilli(), Long.MIN_VALUE, Long.MAX_VALUE
      • toInstant

        public static java.time.Instant toInstant​(java.time.Instant instant)
        Returns the given non-null instant, or Instant.EPOCH if null.
        Parameters:
        instant - The instant to test, may be null.
        Returns:
        The given non-null instant, or Instant.EPOCH if null.
      • toInstant

        public static java.time.Instant toInstant​(java.time.Instant instant,
                                                  java.time.Instant defaultInstant)
        Returns the given non-null instant, or defaultInstant if instant is null.
        Parameters:
        instant - The instant to test, may be null.
        defaultInstant - The default instant to use if the given instant is null, may be null.
        Returns:
        The given non-null instant, or defaultInstant if null.
      • toMillisSince

        public static long toMillisSince​(java.time.Instant instant)
        Converts an Instant to milliseconds since that Instant bound to a long without throwing ArithmeticException.
        • If the duration milliseconds are greater than Long.MAX_VALUE, then return Long.MAX_VALUE.
        • If the duration milliseconds are lesser than Long.MIN_VALUE, then return Long.MIN_VALUE.
        • If the instant is null, treat it as Instant.EPOCH.
        Parameters:
        instant - The instant to convert, not null.
        Returns:
        long The duration in milliseconds since the given Instant.