cowtowncoder / java-uuid-generator

Java Uuid Generator (JUG) is a Java library for generating all standard UUID versions (v1 - v7)
Apache License 2.0
730 stars 104 forks source link

Time based UUID not using current time stamp #18

Closed nagamanikandank closed 8 years ago

nagamanikandank commented 8 years ago

@cowtowncoder , I used the following code Generators.timeBasedGenerator().generate() to generate time based UUID. On the generated UUID, I found the timestamp using Java's UUID.timestamp() , I see the timestamp is not current time . Is there a way to generate UUID with current time stamp?

cowtowncoder commented 8 years ago

@nagamanikandank I don't understand -- timestamp is generated from the current timestamp, but it has to avoid duplicates, as well as translate from milliseconds of current time to 100 nsec (or whatever granularity is as specified by UUID spec), it gets translated to complaint value. So what exactly is your problem? Timestamp in UUID is not meant to be used for knowing current time but merely for providing uniqueness and potentially loose ordering within values produced by a single host.

nagamanikandank commented 8 years ago

@cowtowncoder . I am not very clear in the way I wrote the question I think. Sorry. My Question is , does Generators.timeBasedGenerator().generate() , use the current time to generate UUID, or some random time to generate the Id

cowtowncoder commented 8 years ago

@nagamanikandank It uses current time to generate time/location-based UUID (one produced by timeBasedGenerator()).