Created
April 25, 2014 08:57
-
-
Save stevendaniels/11282739 to your computer and use it in GitHub Desktop.
Extract a timestamp from a UUID created by Hibernate's uuid.hex function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_timestamp_from_hibernate_uuid(str) | |
Time.at(str[16,12].to_i(16) / 1000) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* uuid.hex creates a string of length 32. By default, the UUID it creates | |
* uses "" as a separator, so I'm not sure the exact format of the string, | |
* but it ends up bein something like this: | |
* XXXX-XXXX-XXXX-XXXX-YYYYYYYYYYYY-XXXX | |
* | |
* where YYYYYYYYYYYY is hexidecimal for the unix time. | |
* | |
* Since the UUID is probably in your DB, SQL is a good choice for extracting the timestamp. | |
*/ | |
select | |
FROM_UNIXTIME( | |
CONV( | |
SUBSTR( | |
'8a10a2e5458d3a63014596e3d525020c', | |
17, | |
12), | |
16, 10) /1000, | |
'%Y-%m-%d %h:%i:%s' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment