I'm trying to convert a 'US/Eastern' datetime to be the equivalent for another timezone, like 'US/Central'. It seems that using pytz and astimezone would be a good way to do this from: Converting timezone-aware datetime to local time in Python
import pytz
import datetime as DT
est = pytz.timezone('US/Eastern')
cst = pytz.timezone('US/Central')
I create a datetime object for est:
ny_dt = DT.datetime(2021, 3, 1, 9, 30, 0, 0, est)
Here's the output for ny_dt:
Out[6]: datetime.datetime(2021, 3, 1, 9, 30, tzinfo=<DstTzInfo 'US/Eastern' LMT-1 day, 19:04:00 STD>)
I then try to convert this datetime to instead use the defined cst timezone:
chicago_dt = ny_dt.astimezone(cst)
Here's the output for chicago_dt:
Out[8]: datetime.datetime(2021, 3, 1, 8, 26, tzinfo=<DstTzInfo 'US/Central' CST-1 day, 18:00:00 STD>)
So this converted 930am EST to be 826am CST, which is not correct. It should be 830am CST, or exactly one hour earlier. What is the best way to do this? Thanks!