I am trying to convert UTC time to CST. But I am not getting the output as expected.
Below is my code:
import datetime
import pytz
fmt = '%Y-%m-%d %H:%M:%S %Z%z'
e = pytz.timezone('US/Central')
time_from_utc = datetime.datetime.utcfromtimestamp(int(1607020200))
time_from = time_from_utc.astimezone(e)
time_from.strftime(fmt)
time_to_utc = datetime.datetime.utcfromtimestamp(int(1609785000))
time_to = time_to_utc.astimezone(tz=pytz.timezone('US/Central'))
print(time_from_utc)
print(time_from)
print(time_to_utc)
print(time_to)
Here is the output:
(base) ranjeet@casper:~/Desktop$ python3 ext.py
2020-12-03 18:30:00
2020-12-03 07:00:00-06:00
2021-01-04 18:30:00
2021-01-04 07:00:00-06:00
I was expecting that after conversion, I should get time corresponding to the time of UTC i.e.
2020-12-03 18:30:00
2020-12-03 12:30:00-06:00
since CST is -6 Hours from UTC. Any help is appreciated.