2
In [57]: datetime.datetime(2015,7,7,15,30,tzinfo=pytz.timezone('America/Chicago'))
Out[57]: datetime.datetime(2015, 7, 7, 15, 30, tzinfo=<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>)

Notice the offset, it is saying UTC-6 (e.g -(24-18) ) while the correct offset for Chicago on 2015-7-7 is UTC-5.

Am I missing something here?

leonsas
  • 4,718
  • 6
  • 43
  • 70
  • The API for datetime time zones is busted, because it doesn't give the timezone object the opportunity to adjust itself. – Mark Ransom Jul 08 '15 at 23:07

1 Answers1

4

There are issues with some timezones and pytz which using localise will fix:

import pytz
import datetime
d = datetime.datetime(2015,7,7,15,30)
dt = pytz.timezone('America/Chicago').localize(d)

print(dt)
2015-07-07 15:30:00-05:00

Unfortunately using the tzinfo argument of the standard datetime constructors ‘’does not work’’ with pytz for many timezones.

Scott Skiles
  • 3,647
  • 6
  • 40
  • 64
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321