I have included the following UUID library
compile group: 'com.fasterxml.uuid', name: 'java-uuid-generator', version: '3.1.5'
in my build.
i have some code like this
NoArgGenerator timeBasedGenerator = Generators.timeBasedGenerator()
UUID tuid = timeBasedGenerator.generate()
Timestamp timestamp = new Timestamp ((tuid.timestamp()/1000) as Long)
Date dateTime = new Date (timestamp.getTime())
however when I try and look at the date its nothing like what it should be so for example I get uid fef57eca-7c8b-11e8-bedd-992c2ac3197a was Sun Feb 06 07:55:54 GMT 6327 when today is 30/06/2018
Does anyone know how to correctly extract the real date and time from a time based UUID using the fasterxml.uuid library?
but stumped
ps tried this instead
UUID tuid = timeBasedGenerator.generate()
Long t = tuid.timestamp()
Timestamp timestamp = new Timestamp (t)
Date dateTime = new Date (timestamp.getTime())
which gives a uid ff79d7d9-7cb5-11e8-976c-6ba57a5e9636 and date of Thu Aug 14 11:11:40 BST 4359073
I did some more searching on the web.
I built the following 'simple utility' class that can be expanded as required:
I've added explanatory comment so that you can follow what you had to do to process the UUID timestamp() method into a format that works for normal Java date and time processing.
Why the Java UUID class can't provide the methods one might expect to make a time-based UUID interoperable with the normal java date/time formats based on normal unix epoch is a mystery to me.
I ran a little test script using the above static methods:
and got this
which looked correct for time the script was run.