I'm writing a python script which contains two lines of code converting the date that got passed into the method to UTC time:
print "Timezone: %s" % get_localzone()
date = datetime.now(tz=get_localzone())
print "Local time: %s" % date
utc = pytz.utc
utc_date = date.astimezone(utc)
print "UTC date: %s" % utc_date
and the result is:
Timezone: America/Chicago
Local time: 2015-06-17 14:58:45.224827-05:00
UTC date: 2015-06-17 19:58:45.224827+00:00
As you can see the offset in local time is "-05:00", nothing wrong with it, but when I create a customized datetime object with the same timezone:
date = datetime(2015, 6, 17, 14, 58, 45, tzinfo=get_localzone())
The result becomes:
Timezone: America/Chicago
Local time: 2015-06-17 14:58:45-05:51
The offset changed from "-05:00" to "-05:51". I even used the same time that the first "datetime.now()" generated, and the timezone did not change, would someone please explain to me why is this happening? Thanks!