Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevendaniels/11282739 to your computer and use it in GitHub Desktop.
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.
def extract_timestamp_from_hibernate_uuid(str)
Time.at(str[16,12].to_i(16) / 1000)
end
/*
* 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