Package com.github.f4b6a3.uuid.util
Class UuidTime
- java.lang.Object
-
- com.github.f4b6a3.uuid.util.UuidTime
-
public final class UuidTime extends Object
Utility that provides methods related to timestamps.
-
-
Field Summary
Fields Modifier and Type Field Description static longGREGORIAN_MILLISECONDSstatic longTICKS_PER_MILLISECOND
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longgetCurrentTimestamp()Get the current timestamp with milliseconds precision.static InstanttoInstant(long timestamp)Get the instant of the given timestamp.static longtoTimestamp(long unixMilliseconds)Get the timestamp of a given Unix Epoch milliseconds.static longtoTimestamp(Instant instant)Get the timestamp of a given instant.static longtoUnixMilliseconds(long timestamp)Get the Unix Epoch milliseconds of a given timestmap.
-
-
-
Field Detail
-
GREGORIAN_MILLISECONDS
public static final long GREGORIAN_MILLISECONDS
-
TICKS_PER_MILLISECOND
public static final long TICKS_PER_MILLISECOND
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentTimestamp
public static long getCurrentTimestamp()
Get the current timestamp with milliseconds precision. The UUID timestamp is the number of 100-nanos since 1582-10-15 (Gregorian epoch). ### RFC-4122 - 4.2.1.2. System Clock Resolution The timestamp is generated from the system time, whose resolution may be less than the resolution of the UUID timestamp. If UUIDs do not need to be frequently generated, the timestamp can simply be the system time multiplied by the number of 100-nanosecond intervals per system time interval. (4) A high resolution timestamp can be simulated by keeping a count of the number of UUIDs that have been generated with the same value of the system time, and using it to construct the low order bits of the timestamp. The count will range between zero and the number of 100-nanosecond intervals per system time interval.- Returns:
- the current timestamp
-
toTimestamp
public static long toTimestamp(long unixMilliseconds)
Get the timestamp of a given Unix Epoch milliseconds. The value returned by this method is the number of 100-nanos since 1582-10-15 (Gregorian epoch).- Parameters:
unixMilliseconds- the Unix Epoch milliseconds- Returns:
- the timestamp
-
toUnixMilliseconds
public static long toUnixMilliseconds(long timestamp)
Get the Unix Epoch milliseconds of a given timestmap. The value returned by this method is the number of milliseconds since 1970-01-01 (Unix epoch).- Parameters:
timestamp- a timestamp- Returns:
- the Unix milliseconds
-
toTimestamp
public static long toTimestamp(Instant instant)
Get the timestamp of a given instant. The value returned by this method is the number of 100-nanos since 1582-10-15 (Gregorian epoch).- Parameters:
instant- an instant- Returns:
- the timestamp
-
toInstant
public static Instant toInstant(long timestamp)
Get the instant of the given timestamp.- Parameters:
timestamp- a timestamp- Returns:
- the instant
-
-