0

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Itamar Katz
  • 9,544
  • 5
  • 42
  • 74

1 Answers1

0

This is the code though

import time
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1347517370))
Chetan Vashisth
  • 438
  • 4
  • 14