Friday, November 21, 2025
HomeLanguagesJavaUUID timestamp() Method in Java with Examples

UUID timestamp() Method in Java with Examples

The timestamp() method of UUID class in Java is generally used to get the stamp value associated with a particular UUID.

Syntax:

public long timestamp()

Parameters: This method does not take any parameter.

Return Value: This method returns the time stamp value of this UUID.

Exception: This method throws UnsupportedOperationException if this UUID is not a part of version 1 UUID.

Below programs illustrate the working of timestamp() method:

Program 1:




// Java code to illustrate timestamp() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating two UUIDs
        UUID UUID_1
            = UUID
                  .fromString(
                      "58e0a7d7-eebc-11d8-9669-0800200c9a66");
  
        // Displaying the UUID
        System.out.println("UUID: "
                           + UUID_1);
  
        // Displaying the timestamp value
        System.out.println("The timestamp value is: "
                           + UUID_1.timestamp());
    }
}


Output:

UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66
The timestamp value is: 133118681719810007

Program 2:




// Java code to illustrate timestamp() method
  
import java.util.*;
  
public class UUID_Demo {
    public static void main(String[] args)
    {
  
        // Creating two UUIDs
        UUID UUID_1
            = UUID
                  .fromString(
                      "5fc03087-d265-11e7-b8c6-83e29cd24f4c");
  
        // Displaying the UUID
        System.out.println("UUID: "
                           + UUID_1);
  
        // Displaying the timestamp Value
        System.out.println("The timestamp value is: "
                           + UUID_1.timestamp());
    }
}


Output:

UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The timestamp value is: 137309646498050183
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6783 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7167 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS