In our java application we are trying to get the unix time from the type 1 uuid. But its not giving the correct date time values.
long time = uuid.timestamp();
time = time / 10000L; // Dividing by 10^4 as its in 100 nanoseconds precision
Calendar c = Calendar.getInstance();
c.setTimeInMillis(time);
c.getTime();
Can some one please help ?
Edit: Fixed the divisor(10^4)
In my case, the following code worked.
If you using datastax driver, it's:
UUIDs.unixTimestamp(uuid)
http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/utils/UUIDs.html#unixTimestamp(java.util.UUID)
From the docs for
timestamp()
:So you need to offset it from that. For example:
In the case someone else needs it:
https://github.com/f4b6a3/uuid-creator