Re: time module question - time zones
- From: "Eric Wertman" <ewertman@xxxxxxxxx>
- Date: Wed, 21 May 2008 12:40:27 -0400
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.
Thanks!
On Wed, May 21, 2008 at 12:23 PM, Eric Wertman <ewertman@xxxxxxxxx> wrote:
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
something:
#!/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.
TIA
Eric
- Prev by Date: Re: Newbie: Keep TCP socket open
- Next by Date: Re: Python and Flaming Thunder
- Previous by thread: time module question - time zones
- Next by thread: Re: can someone with guessing a number
- Index(es):
Relevant Pages
|