timestamp - Extract the time from a UUID v1 in python -


I have some UUIDs that are randomly generated in my program, but I want to remove the timestamp Being able to generate UUID for testing purposes I saw that using the fields accessor I can get different parts of the timestamp but I do not know how to combine them.

you are viewing in /usr/lib/python2.6/uuid.py

DEF UUID1 (node ​​= none, clock_s = = none): ... nanoseconds = int (time.time () * 1e 9) # 0x01b21dd213814000 # UUID era 1582-10-15 00:00 : 00 and the number of 100-NS intervals between the Unix era is 197-01 -01 00:00:00. Timestamp = int (nanoseconds / 100) + 0x01b21dd213814000L

Resolved equation for time. Time (), you will get

  time.time () as-volume = ((Timestamp - 0x01b21dd213814000L) * 100 / 1e 9)  

then use Do:

  in [3]: Import into UUID [4]: ​​in U = uuid.uuid1 () [58]: datetime.datetime.fromtimestamp ((u.time - 0x01b21dd213814000L) * 100 / 1e 9) Out [58]: datetime.datetime (2010, 9, 25, 17, 43, 6, 298623)  

This uuid.uuid1 .

gives the date-time associated with the UUID generated by

Comments