By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,172 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,172 IT Pros & Developers. It's quick & easy.

Re: time module question - time zones

P: n/a
Sorry, my time zone is +4, not minus 4, which means that something
else is causing my source data to be in the future. I still do need
to understand where the time routines determine the time zone offset,
so I can be sure I'm passing around the neutral value.

On Wed, May 21, 2008 at 12:23 PM, Eric Wertman <ew******@gmail.comwrote:
I tend to deal with dates a lot in different formats and places...
typically I'll convert them to a time tuple with strptime(), and pass
them around like that before I need to write them back out.

One set of time/dates I'm getting are in UTC, but the string doesn't
say that specifically. So I do this.. I had expected the outcome to
be offset properly (I'm EST5EDT). But I'm obviously missing

#!/usr/bin/env python

import time

utc_str = '2008-05-10 03:05:00 UTC'

d = time.strptime(utc_str,'%Y-%m-%d %H:%M:%S %Z')
t = time.mktime(d)

print d
print time.gmtime(t)
print time.localtime(t)

output :

(2008, 5, 10, 3, 5, 0, 5, 131, 0)
(2008, 5, 10, 8, 5, 0, 5, 131, 0)
(2008, 5, 10, 4, 5, 0, 5, 131, 1)
I believe that I should be getting (2008, 5, 9, 23, 5, 0, 5, 130, 1)
out of one of those, since the original 3:05am time was UTC, and my TZ
is currently -4. Does that make sense? I didn't even think I needed
to do any business with time.localtime() and time.gmtime(). I
expected time.strftime() to return the locale appropriate time, but
it didn't.


Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.