Hey guys, I'm writing a script that is retrieving information from places.sqlite (history) and realized that it store the time in PRTime format. Is there a method available in python which could convert this date time or do i have to make it myself?
A:
there isn't any built-in method, but it does seem quite trivial to implement:
>>> t = 1221842272303080
>>> t /= 1e6
>>> t
1221842272.30308
>>> import datetime
>>> datetime.datetime.fromtimestamp(t)
datetime.datetime(2008, 9, 19, 17, 37, 52, 303080)
The result is local time, for UTC you could do:
>>> import time
>>> time.gmtime(t)
time.struct_time(tm_year=2008, tm_mon=9, tm_mday=19, tm_hour=16, tm_min=37, tm_sec=52, tm_wday=4, tm_yday=263, tm_isdst=0)
That's py3k output, it might differ slightly in python 2.x
SilentGhost
2010-03-25 13:25:50
Thanks just making sure i'm not re inventing the wheel
Michael Grech
2010-03-25 13:33:22
+1
A:
PRTime is number of microseconds sine 1-Jan-1970 (https://developer.mozilla.org/en/PRTime) so just do this to get UTC time
datetime.datetime(1970, 1, 1) + datetime.timedelta(microseconds=pr_time)
e.g.
print datetime.datetime(1970, 1, 1) + datetime.timedelta(microseconds=time.time()*1000*1000)
output:
2010-03-25 13:30:02.243000
Anurag Uniyal
2010-03-25 13:26:28