[Tutor] time zone conversion

spawgi at gmail.com spawgi at gmail.com
Tue Aug 2 00:24:49 CEST 2011


Quick question - Is any daylight saving taken into consideration for this?

On Tue, Aug 2, 2011 at 1:35 AM, ian douglas <ian.douglas at iandouglas.com>wrote:

> 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  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
http://spawgi.wordpress.com
We can do it and do it better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110802/8b33efc8/attachment.html>


More information about the Tutor mailing list