I want to convert a datetime object in python 2.7, from UTC time to Unix (aka epoch) time. As far as I understand, the following should give me back the timestamp I started with (ts -> UTC -> ts):
from datetime import datetime
from dateutil import tz
datetime.fromtimestamp(1538000000, tz.tzutc()).strftime('%s')
However, the output is different:
'1537992800'
(I am using fromtimestamp
and not utcfromtimestamp
as the latter returns a naive (unaware) object).