I'm simply trying to take a naïve time, give it a local time zone, and then convert it into UTC.
I'm using the following code:
create_time_local = parser.parse(timestring).replace(tzinfo=timezone('America/Chicago'))
create_time_utc = create_time_local.astimezone(timezone('UTC'))
print('+++++++++' + timestring + '++++++++')
print('*****************' + create_time_local.strftime(fmt) + '***************')
print('-----' + create_time_utc.strftime(fmt) + '-----')
I can't figure out why, but here's the output:
+++++++++09/20/15 2:00:00 AM++++++++
*****************09/20/15 02:00:00 AM*************** -----09/20/15 07:51:00 AM-----
The correct answer, of course, should be 7:00 AM. I can't figure out why it's coming out 7:51 AM.
Alternate working code besides the linked code in the duplicate:
create_time_local_naive = parser.parse(timestring)
local_tz = timezone('America/Chicago')
create_time_local = local_tz.localize(create_time_local_naive)
create_time_utc = create_time_local.astimezone(timezone('UTC'))