You need to use the .localize()
method to put a datetime in the correct timezone, otherwise a historical offset is chosen by mistake:
ChengduTZ = pytz.timezone('Asia/Chongqing')
MidnightInChengdu = ChengduTZ.localize(datetime.datetime(2013, 6, 5, 0, 0, 0, 0))
MidnightInNewYork = NewYorkTZ.localize(datetime.datetime(2013, 6, 5, 0, 0, 0, 0))
See the pytz
documenation:
Unfortunately using the tzinfo argument of the standard datetime constructors ‘’does not work’’ with pytz for many timezones.
With this change, the output becomes:
When it's midnight in Chengdu it's:
2013-06-05 00:00:00+08:00
2013-06-04 17:00:00+01:00
2013-06-04 18:00:00+02:00
2013-06-04 12:00:00-04:00
When it's midnight in New York it's:
2013-06-05 00:00:00-04:00
2013-06-05 05:00:00+01:00
2013-06-05 06:00:00+02:00
2013-06-05 12:00:00+08:00
Note that the New York offsets were also incorrect.