[Tutor] time zone conversion

ian douglas ian.douglas at iandouglas.com
Mon Aug 1 22:05:07 CEST 2011

Hi all,

Been trying to wrap my head around some datetime vs time stuff with 
regards to parsing a string as a date plus time with a timezone offset.

This is the string I'm given:


And I can use time.strptime to parse out its individual elements, but 
then I need to adjust that time, in UTC/Zulu to my local time zone.

Here's what I'm currently trying:

         old_launch_time = '2010-01-22T00:14:33.000Z'
         os.environ['TZ'] = 'UTC'
         launch_time = time.strptime(old_launch_time, 
         os.environ['TZ'] = 'US/Pacific'
         print 'old time: ' + old_launch_time
         print 'new time: ' + time.strftime("%Y-%m-%d %H:%M:%S", 


old time: 2010-01-22T00:14:33.000Z
new time: 2010-01-22 00:14:33

But the different tzset() calls are not adjusting based on the 7 or 8 
hour difference.

I know that all incoming dates/times are coming to me in UTC. I just 
can't seem to get a good handle on how to properly convert it to my own 
time zone.


More information about the Tutor mailing list