Python pytz timezone function returns a timezone that is off by 9 minutes

Answer based on the answer by Carl Meyer in Google Groups Answer

The reason for this difference, is that this is NOT the right way of converting a timezone agnostic datetime object to a timezone aware object.

The explanation being:

“A pytz timezone class does not represent a single offset from UTC, it
represents a geographical area which, over the course of history, has
probably gone through several different UTC offsets. The oldest offset
for a given zone, representing the offset from before time zones were
standardized (in the late 1800s, most places) is usually called “LMT”
(Local Mean Time), and it is often offset from UTC by an odd number of
minutes.”

(quote from the cited answer in Google Groups)

Basically, you should do:

from datetime import datetime
import pytz

my_datetime = datetime(2015, 6, 11, 13, 30)
my_tz = pytz.timezone('America/Chicago')    
good_dt = my_tz.localize(my_datetime)

print(good_dt)

out: 2015-06-11 13:30:00-05:00

Leave a Comment