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/.
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/.
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)
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.
1267488000000
is a epoch timestamp with milliseconds. It is "Tue Mar 02 2010 08:00:00 GMT+0800 (WST)"
(where I live, at least)
This is almost certainly a timestamp (the number of milliseconds since the epoch). You want date.fromtimestamp(timestamp)
to make sense of it.
This is probably a Unix timestamp. See here for some time conversions in python.
It's in miliseconds from epoch (but rounded to tousends of seconds). Try using:
datetime.datetime.fromtimestamp(timestamp / 1000)
Try this:
import datetime
datetime.datetime.fromtimestamp(1267488000000/1000)
Note that the Javascript Date object and the Java Date class both use milliseconds since Jan 1 1970 GMT. Both languages are commonly used in web services.