Getting timestamp from v1 uuid

Getting timestamp from v1 uuid

Translated from J.B. Langston’s Converting TimeUUID Strings to Dates Java version to Python:

import arrow
import fileinput
import uuid

def main():
    for line in fileinput.input():
        line = line.rstrip()
        value = uuid.UUID(line)
        epoch_millis = (value.time - 0x01b21dd213814000) / 10000
        epoch = epoch_millis / 1000
        ts = arrow.get(epoch)
        print(ts)

if __name__ == "__main__":
    main()
Advertisement
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s