Skip to content

Instantly share code, notes, and snippets.

@userid
Last active May 24, 2017 11:15
Show Gist options
  • Select an option

  • Save userid/ab8e263d8d0af407da329a4fd93e6df1 to your computer and use it in GitHub Desktop.

Select an option

Save userid/ab8e263d8d0af407da329a4fd93e6df1 to your computer and use it in GitHub Desktop.
extract a date from a UUID type1 using Perl?
#!/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

userid commented May 24, 2017

Copy link
Copy Markdown
Author
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import time
import uuid

u1 = uuid.UUID('ed976b76-406a-11e7-acdf-7745c9ffa1a7')

timestamp = u1.time/10000000 - 12219292800

localtime = time.asctime(time.localtime(timestamp))
print "Time: %s" % localtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment