1

I'm trying to find an equivalent option of "uuid -d" linux command in python, and end up using below, as found in Extract the time from a UUID v1 in python :

request_id = 78577992-6170-11e8-a1e4-f3a982af936e
request_uuid = uuid.UUID(request_id)
print (datetime.fromtimestamp((request_uuid.time - 0x01b21dd213814000L)*100/1e9))

which printed the time as "2018-05-27 15:40:31.803023", which is different from the actual time shows up in "uuid -d" command:

uuid -d 78577992-6170-11e8-a1e4-f3a982af936e |grep "content: time:"
    content: time:  2018-05-27 05:40:31.803022.6 UTC

Is there a correct option to extract time information from UUID in python, using uuid or any built-in modules?

Danny
  • 151
  • 2
  • 12

1 Answers1

0

Your provided request_id is different from the uuid you test using uuid -d. If you correct this discrepancy they correspond (checked using answers to Extract the time from a UUID v1 in python).

twolffpiggott
  • 1,063
  • 8
  • 13
  • My bad.. corrected the question with actual UUID I'm dealing with. – Danny May 27 '18 at 19:23
  • 2
    And, that was it!!, partly because it was a wrong UUID I used to compare, and partly it was because "uuid -d" was printing the time in UTC, and UUID in python in local timezone. Once i wrapped up the extracted time with "datetime.utcfromtimestamp", it shows up correctly. Thanks for the pointers. – Danny May 27 '18 at 19:31