views:

346

answers:

9

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/.

+5  A: 

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)
The MYYN
+13  A: 

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.

FogleBird
Fantastico! Thanks all.
twneale
But it's not a datetime instance
baloo
Updated to include datetime, including a note on timezone differences between the two approaches.
FogleBird
....and in the end it's going to turn out that the New York State Senate was just thinking *really* far ahead.
Pekka
+2  A: 

1267488000000 is a epoch timestamp with milliseconds. It is "Tue Mar 02 2010 08:00:00 GMT+0800 (WST)" (where I live, at least)

Delan Azabani
You may want to check this. Your date looks very much like today's, where this lloks like 02 March 2010, *viz.* `>>> import datetime>>> print datetime.datetime.fromtimestamp(1267488000000/1000)2010-03-02 11:00:00`
Johnsyweb
Thanks. I used JavaScript to get it and used `Date()` instead of `new Date()`, which caused the mishap.
Delan Azabani
Fixed. Thanks again.
Delan Azabani
+1  A: 

This is almost certainly a timestamp (the number of milliseconds since the epoch). You want date.fromtimestamp(timestamp) to make sense of it.

Kilian Foth
+1  A: 

This is probably a Unix timestamp. See here for some time conversions in python.

kgiannakakis
+3  A: 

It's in miliseconds from epoch (but rounded to tousends of seconds). Try using:

datetime.datetime.fromtimestamp(timestamp / 1000)
zefciu
+4  A: 

Try this:

import datetime
datetime.datetime.fromtimestamp(1267488000000/1000)
baloo
+3  A: 

This is pretty informative. I think you have a time stamp in milliseconds since Thursday, January 1st, 1970.

unwind
+2  A: 

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.

Jason S
Thank you--and this web service was indeed written in java.
twneale