How to generate time based UUIDs?

dogfish picture dogfish · Aug 15, 2013 · Viewed 57.9k times · Source

I want to generate time-based universally unique identifier (UUID) in Java.

The method java.util.UUID.randomUUID() generates a UUID Version 4 where 122 of the 128 bits are from a cryptographically-strong random number generator.

How to generate a Version 1 (time based) UUID ? Is there a separate library for that or is it some how provided in the Java 7 API and I am missing it.

Answer

Avinash Mishra picture Avinash Mishra · Mar 30, 2017
String timeuuid = com.datastax.driver.core.utils.UUIDs.timeBased().toString();

have a look at https://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/utils/UUIDs.html