Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 13th, 2008, 03:25 PM
Kent Tenney
Guest
 
Posts: n/a
Default datetime from uuid1 timestamp

Howdy,

I have not found a routine to extract usable
date/time information from the 60 bit uuid1 timestamp.

Is there not a standard solution?

Thanks,
Kent

  #2  
Old August 13th, 2008, 05:25 PM
gordyt
Guest
 
Posts: n/a
Default Re: datetime from uuid1 timestamp

Howdy Kent,

Interesting question! Give this a shot:

import datetime
import time
import uuid

# get offset in seconds between the UUID timestamp Epoch (1582-10-15)
and
# the Epoch used on this computer
DTD_SECS_DELTA = (datetime.datetime(*time.gmtime(0)[0:3])-
datetime.datetime(1582, 10, 15)).days * 86400
def uuid1_to_ts(u):
"""Return a datetime.datetime object that represents the timestamp
portion of a uuid1.

Parameters:
u -- a type 1 uuid.UUID value

Example usage:

print uuid1_to_ts(uuid.uuid1())
"""
secs_uuid1 = u.time / 1e7
secs_epoch = secs_uuid1 - DTD_SECS_DELTA
return datetime.datetime.fromtimestamp(secs_epoch)


--gordon
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles