On this page

Instants

public class org.apache.commons.lang3.time.Instants[source]

Works with Instants.

Since:

3.21.0

Methods

toEpochMillis(Instant)

Converts an Instant to milliseconds bound to a long without throwing ArithmeticException.

toInstant(Instant)

Returns the given non-null instant, or Instant#EPOCH if null.

toInstant(Instant, Instant)

Returns the given non-null instant, or defaultInstant if instant is null.

toMillisSince(Instant)

Converts an Instant to milliseconds since that Instant bound to a long without throwing ArithmeticException.

public static long toEpochMillis(Instant instant)[source]

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:
public static Instant toInstant(Instant instant)[source]

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.

public static Instant toInstant(Instant instant, Instant defaultInstant)[source]

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.

public static long toMillisSince(Instant instant)[source]

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.