Java UUID.timestamp() method example

Java UUID.timestamp() method example

By technicalkeeda, Views 745, Date 21-Feb-2018

In this tutorial, You will learn how to get the timestamp value of this UUID. Java UUID.timestamp() method throws UnsupportedOperationException - If this UUID is not a version 1 UUID.

tags Java

The timestamp value associated with this UUID. The 60 bit timestamp value is constructed from the time_low, time_mid, and time_hi fields of this UUID. The resulting timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.

syntax

public long timestamp()

Throws

UnsupportedOperationException - If this UUID is not a version 1 UUID.

Java UUID timestamp() example

  • Initialize the String String name = "6224c18d-d004-11bd-984e-b8d80b2bdff8";
  • UUID.fromString(name); It creates a UUID from the string standard representation.
  • uuid.version(); It returns the version number of this UUID.
  • uuid.timestamp(); It returns the timestamp value associated with this UUID.
package com.technicalkeeda;

import java.util.UUID;

public class App {

    public static void main(String[] args) {

        String name = "6224c18d-d004-11bd-984e-b8d80b2bdff8";
        UUID uuid = UUID.fromString(name);

        System.out.println("The version number of UUID is :-  " + uuid.version());
        System.out.println("Time stamp value :-  " + uuid.timestamp());
    }
}

output

The version number of UUID is :-  1
Time stamp value :-  125485081881264525

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]