Last active
May 24, 2017 11:15
-
-
Save userid/ab8e263d8d0af407da329a4fd93e6df1 to your computer and use it in GitHub Desktop.
extract a date from a UUID type1 using Perl?
This file contains hidden or 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
| #!/usr/bin/perl | |
| $uuid= shift || 'ef802820-46b3-11e2-bf3a-47ef6b3e28e2'; | |
| $uuid =~ s/-//g; | |
| my $timelow = hex substr( $uuid, 2 * 0, 2 * 4 ); | |
| my $timemid = hex substr( $uuid, 2 * 4, 2 * 2 ); | |
| my $version = hex substr( $uuid, 2 * 6, 1 ); | |
| my $timehi = hex substr( $uuid, 2 * 6 + 1, 2 * 2 - 1 ); | |
| my $time = ( $timehi * ( 2**16 ) + $timemid ) * ( 2**32 ) + $timelow; | |
| my $epoc = int( $time / 10000000 ) - 12219292800; | |
| my $nano = $time - int( $time / 10000000 ) * 10000000; | |
| #$time_date = scalar localtime $epoc; | |
| #print strftime( '%d-%m-%Y %H:%M:%S', localtime($epoc) ); | |
| print "\n Time: ", scalar localtime $epoc, " +", $nano / 10000, "ms\n"; |
userid
commented
May 24, 2017
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment