- java.lang.Object
-
- com.github.f4b6a3.uuid.util.UuidTime
-
public final class UuidTime extends Object
Utility for UUID time stamps.The UUID time stamp is a 60-bit number.
The UUID time stamp resolution is 100ns, i.e., the UUID clock ticks every 100-nanosecond interval.
In JDK 8,
Instant.now()has millisecond precision, in spite ofInstanthas nanoseconds resolution. In JDK 9+,Instant.now()has microsecond precision.
-
-
Field Summary
Fields Modifier and Type Field Description static InstantEPOCH_GREGThe Gregorian epoch.static longEPOCH_GREG_SECONDSThe Gregorian epoch in seconds.static InstantEPOCH_UNIXThe Unix epoch.static longEPOCH_UNIX_SECONDSThe Unix epoch in seconds.static longNANOS_PER_TICKNumber nanos per clock tick.static longTICKS_PER_MILLINumber of clock ticks per millisecond.static longTICKS_PER_SECONDNumber of clock ticks per second.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InstantfromGregTimestamp(long gregTimestamp)Converts a number of 100ns since 1582-10-15 (Gregorian epoch) into anInstant.static InstantfromUnixTimestamp(long unixTimestamp)Converts a number of 100ns since 1970-01-01 (Unix epoch) into anInstant.static longgetGregTimestamp()Returns the number of 100ns since 1582-10-15 (Gregorian epoch).static longgetUnixTimestamp()Returns the number of 100ns since 1970-01-01 (Unix epoch).static longtoGregTimestamp(long unixTimestamp)Converts a number of 100ns since 1970-01-01 (Unix epoch) into a number of 100ns since 1582-10-15 (Gregorian epoch).static longtoGregTimestamp(Instant instant)Converts anInstantinto a number of 100ns since 1582-10-15 (Gregorian epoch).static longtoUnixTimestamp(long gregTimestamp)Converts a number of 100ns since 1582-10-15 (Gregorian epoch) into a number of 100ns since 1970-01-01 (Unix epoch).static longtoUnixTimestamp(Instant instant)Converts anInstantinto a number of 100ns since 1970-01-01 (Unix epoch).
-
-
-
Field Detail
-
EPOCH_UNIX
public static final Instant EPOCH_UNIX
The Unix epoch.
-
EPOCH_GREG
public static final Instant EPOCH_GREG
The Gregorian epoch.
-
EPOCH_UNIX_SECONDS
public static final long EPOCH_UNIX_SECONDS
The Unix epoch in seconds.
-
EPOCH_GREG_SECONDS
public static final long EPOCH_GREG_SECONDS
The Gregorian epoch in seconds.
-
NANOS_PER_TICK
public static final long NANOS_PER_TICK
Number nanos per clock tick.- See Also:
- Constant Field Values
-
TICKS_PER_MILLI
public static final long TICKS_PER_MILLI
Number of clock ticks per millisecond.- See Also:
- Constant Field Values
-
TICKS_PER_SECOND
public static final long TICKS_PER_SECOND
Number of clock ticks per second.- See Also:
- Constant Field Values
-
-
Method Detail
-
getUnixTimestamp
public static long getUnixTimestamp()
Returns the number of 100ns since 1970-01-01 (Unix epoch).It uses
Instant.now()to get the the current time.- Returns:
- a number of 100ns since 1970-01-01 (Unix epoch).
-
getGregTimestamp
public static long getGregTimestamp()
Returns the number of 100ns since 1582-10-15 (Gregorian epoch).It uses
Instant.now()to get the the current time.- Returns:
- a number of 100ns since 1582-10-15 (Gregorian epoch).
-
toUnixTimestamp
public static long toUnixTimestamp(long gregTimestamp)
Converts a number of 100ns since 1582-10-15 (Gregorian epoch) into a number of 100ns since 1970-01-01 (Unix epoch).- Parameters:
gregTimestamp- a number of 100ns since 1582-10-15 (Gregorian epoch)- Returns:
- a number of 100ns since 1970-01-01 (Unix epoch)
-
toGregTimestamp
public static long toGregTimestamp(long unixTimestamp)
Converts a number of 100ns since 1970-01-01 (Unix epoch) into a number of 100ns since 1582-10-15 (Gregorian epoch).- Parameters:
unixTimestamp- a number of 100ns since 1970-01-01 (Unix epoch)- Returns:
- a number of 100ns since 1582-10-15 (Gregorian epoch).
-
toUnixTimestamp
public static long toUnixTimestamp(Instant instant)
Converts anInstantinto a number of 100ns since 1970-01-01 (Unix epoch).- Parameters:
instant- an instant- Returns:
- a number of 100ns since 1970-01-01 (Unix epoch).
-
toGregTimestamp
public static long toGregTimestamp(Instant instant)
Converts anInstantinto a number of 100ns since 1582-10-15 (Gregorian epoch).- Parameters:
instant- an instant- Returns:
- a number of 100ns since 1582-10-15 (Gregorian epoch).
-
fromUnixTimestamp
public static Instant fromUnixTimestamp(long unixTimestamp)
Converts a number of 100ns since 1970-01-01 (Unix epoch) into anInstant.- Parameters:
unixTimestamp- a number of 100ns since 1970-01-01 (Unix epoch)- Returns:
- an instant
-
-