473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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

Aug 13 '08 #1
1 3867
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
Aug 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joshua Beall | last post by:
Hi All, Any thoughts on the easiest way to translate a MySQL timestamp (which looks like 20040422090941) to the datetime format (which looks like 2004-04-22 09:09:41). This is just to make it...
3
by: Martin Bless | last post by:
Below is what I'm currently using to construct datatime objects from strings. Date and time objects are made up similar. To and from string conversions are frequently needed in SQL neighborhood. ...
0
by: qwerty_1997 | last post by:
Hi, I can't work out exactly what I need to do with datetime and timestamp, can anyone help? I would like a column created_timestamp to be populated on record creation (and preferably not...
1
by: Chris | last post by:
Hello, I'm having some problems right now with something that would seem to be rather simple (and probably is). But, the solution is escaping me right now. Currently, I have created a data...
2
by: John Reese | last post by:
Hi. >>> import time, calendar, datetime >>> n= 1133893540.874922 >>> datetime.datetime.fromtimestamp(n) datetime.datetime(2005, 12, 6, 10, 25, 40, 874922) >>> lt= _ >>>...
11
by: Rubic | last post by:
I was a little surprised to recently discover that datetime has no method to input a string value. PEP 321 appears does not convey much information, but a timbot post from a couple years ago...
5
by: Simen Haugen | last post by:
Hi. How can I convert a python datetime to a timestamp? It's easy to convert a timestamp to datetime (datetime.datetime.fromtimestamp(), but the other way around...?) -Simen
6
by: Brandon | last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a...
2
by: Kent Tenney | last post by:
Howdy, I submitted an ASPN recipe to do it. http://code.activestate.com/recipes/576420/
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.