Class Instants

java.lang.Object
org.apache.commons.lang3.time.Instants

public class Instants extends Object
Works with Instants.
Since:
3.21.0
  • Method Details

    • toEpochMillis

      public static long toEpochMillis(Instant instant)
      Converts an Instant to milliseconds bound to a long without throwing ArithmeticException.
      Parameters:
      instant - The instant to convert, not null.
      Returns:
      long The given Instant in milliseconds.
      See Also:
    • toInstant

      public static Instant toInstant(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 Instant toInstant(Instant instant, 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(Instant instant)
      Converts an Instant to milliseconds since that Instant bound to a long without throwing ArithmeticException.
      Parameters:
      instant - The instant to convert, not null.
      Returns:
      long The duration in milliseconds since the given Instant.