time module question - time zones

E

Eric Wertman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top