Welcome, guest | Sign In | My Account | Store | Cart

The uuid timestamp is 60 bits, the number of 100 nanosecond increments since Oct. 15, 1582 This simple function returns a value which makes datetime.datetime.fromtimestamp() happy.

It simply rewinds the code in the standard library's uuid1 function:

nanoseconds = int(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) + 0x01b21dd213814000
Python, 8 lines
1
2
3
4
5
6
7
8
def get_posixtime(uuid1):
    """Convert the uuid1 timestamp to a standard posix timestamp
    """
    assert uuid1.version == 1, ValueError('only applies to type 1')
    t = uuid1.time
    t = t - 0x01b21dd213814000
    t = t / 1e7
    return t
Created by Kent Tenney on Wed, 13 Aug 2008 (MIT)
Python recipes (4591)
Kent Tenney's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks