Looking inside /usr/lib/python2.6/uuid.py you'll see
def uuid1(node=None, clock_seq=None):
...
nanoseconds = int(time.time() * 1e9)
# 0x01b21dd213814000 is the number of 100-ns intervals between the
# UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
timestamp = int(nanoseconds/100) + 0x01b21dd213814000L
solving the equations for time.time(), you'll get
time.time()-like quantity = ((timestamp - 0x01b21dd213814000L)*100/1e9)
So use:
In [3]: import uuid
In [4]: u = uuid.uuid1()
In [58]: datetime.datetime.fromtimestamp((u.time - 0x01b21dd213814000L)*100/1e9)
Out[58]: datetime.datetime(2010, 9, 25, 17, 43, 6, 298623)
This gives the datetime associated with a UUID generated by uuid.uuid1
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…