Per convertire da un timestamp UNIX a un oggetto datetime Python, usa datetime.fromtimestamp()
(documentazione
).
>>> from datetime import datetime
>>> datetime.fromtimestamp(0)
datetime.datetime(1970, 1, 1, 1, 0)
>>> datetime.fromtimestamp(1268816500)
datetime.datetime(2010, 3, 17, 10, 1, 40)
Da Python datetime a UNIX timestamp:
>>> import time
>>> time.mktime(datetime(2010, 3, 17, 10, 1, 40).timetuple())
1268816500.0