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:

2010-01-22T00:14:33.000Z

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'
        time.tzset()
launch_time = time.strptime(old_launch_time, '%Y-%m-%dT%H:%M:%S.000Z')
        os.environ['TZ'] = 'US/Pacific'
        time.tzset()
        print 'old time: ' + old_launch_time
print 'new time: ' + time.strftime("%Y-%m-%d %H:%M:%S", launch_time)

output:

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.

Thanks,
Ian

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to