Convert timestamp since epoch to datetime.datetime

I would use the time module

>>> import time
>>> time.gmtime(1346114717972/1000.)
time.struct_time(tm_year=2012, tm_mon=8, tm_mday=28, tm_hour=0, tm_min=45, tm_sec=17, tm_wday=1, tm_yday=241, tm_isdst=0)  

This shows the timestamp in UTC/GMT time.

The timestamp is divided by 1000 as the stamps you have provided are in milliseconds since the epoch, not seconds.

Then use strftime to format like so:

>>> time.strftime('%m/%d/%Y %H:%M:%S',  time.gmtime(1346114717972/1000.))
'08/28/2012 00:45:17'

Leave a Comment