For at konvertere fra et UNIX-tidsstempel til et Python-datetime-objekt skal du bruge datetime.fromtimestamp()
(dokumentation
).
>>> 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)
Fra Python datetime til UNIX-tidsstempel:
>>> import time
>>> time.mktime(datetime(2010, 3, 17, 10, 1, 40).timetuple())
1268816500.0