Package org.apache.commons.lang3.time
Class Instants
- java.lang.Object
-
- org.apache.commons.lang3.time.Instants
-
public class Instants extends java.lang.ObjectWorks withInstants.- Since:
- 3.21.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longtoEpochMillis(java.time.Instant instant)Converts an Instant to milliseconds bound to alongwithout throwingArithmeticException.static java.time.InstanttoInstant(java.time.Instant instant)Returns the given non-null instant, orInstant.EPOCHif null.static java.time.InstanttoInstant(java.time.Instant instant, java.time.Instant defaultInstant)Returns the given non-null instant, ordefaultInstantif instant is null.static longtoMillisSince(java.time.Instant instant)Converts an Instant to milliseconds since that Instant bound to alongwithout throwingArithmeticException.
-
-
-
Method Detail
-
toEpochMillis
public static long toEpochMillis(java.time.Instant instant)
Converts an Instant to milliseconds bound to alongwithout throwingArithmeticException.- If the duration milliseconds are greater than
Long.MAX_VALUE, then returnLong.MAX_VALUE. - If the duration milliseconds are lesser than
Long.MIN_VALUE, then returnLong.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
- If the duration milliseconds are greater than
-
toInstant
public static java.time.Instant toInstant(java.time.Instant instant)
Returns the given non-null instant, orInstant.EPOCHif null.- Parameters:
instant- The instant to test, may be null.- Returns:
- The given non-null instant, or
Instant.EPOCHif null.
-
toInstant
public static java.time.Instant toInstant(java.time.Instant instant, java.time.Instant defaultInstant)Returns the given non-null instant, ordefaultInstantif 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
defaultInstantif null.
-
toMillisSince
public static long toMillisSince(java.time.Instant instant)
Converts an Instant to milliseconds since that Instant bound to alongwithout throwingArithmeticException.- If the duration milliseconds are greater than
Long.MAX_VALUE, then returnLong.MAX_VALUE. - If the duration milliseconds are lesser than
Long.MIN_VALUE, then returnLong.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.
- If the duration milliseconds are greater than
-
-