Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What the heck kind of timestamp is this: 1267488000000

And how do I convert it to a datetime.datetime instance in python?

It's the output from the New York State Senate's API: http://open.nysenate.gov/legislation/.

like image 624
twneale Avatar asked May 25 '10 13:05

twneale


2 Answers

It looks like Unix time, but with milliseconds instead of seconds?

>>> import time
>>> time.gmtime(1267488000000 / 1000)
time.struct_time(tm_year=2010, tm_mon=3, tm_mday=2, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=61, tm_isdst=0)

March 2nd, 2010?

And if you want a datetime object:

>>> import datetime
>>> datetime.datetime.fromtimestamp(1267488000000 / 1000)
datetime.datetime(2010, 3, 1, 19, 0)

Note that the datetime is using the local timezone while the time.struct_time is using UTC.

like image 162
FogleBird Avatar answered Oct 15 '22 18:10

FogleBird


Maybe milliseconds?

>>> import time
>>> time.gmtime(1267488000000/1000)
time.struct_time(tm_year=2010, tm_mon=3, tm_mday=2, \
    tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=61, tm_isdst=0)
like image 25
miku Avatar answered Oct 15 '22 19:10

miku