Java UUID - timestamp() Method
The java.util.UUID.timestamp() method returns the timestamp value associated with this UUID. The timestamp value is only meaningful in a time-based UUID, which has version type 1. If this UUID is not a time-based UUID then this method throws UnsupportedOperationException.
Syntax
public long timestamp()
Parameters
No parameter is required.
Return Value
Returns the timestamp value associated with this UUID.
Exception
Throws UnsupportedOperationException, if this UUID is not a version 1 UUID.
Example:
In the example below, the java.util.UUID.timestamp() method returns the timestamp value associated with the given UUID.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating an UUID UUID uid = UUID.fromString("d81e4f2e-cdf2-10e6-529b-7df92533d1cb"); //printing the hash code of the uuid System.out.println("Time Stamp value: " + uid.timestamp()); } }
The output of the above code will be:
Time Stamp value: 64965687535095598
❮ Java.util - UUID