time module: round tripping

Anoop Aryal aryal at ameritech.net
Mon Jun 16 11:54:26 EDT 2003


Hi,
i'm not sure if this is the right place to post it. if it's not, i would 
appriciate it if you could point me to the right newsgroup.

i had needed to do some time manipulation -- take the unix time value, 
convert it to localtime (human readable format), save it to a text file. 
later, read it from the text file, convert it back to unix time format 
for comparisions. it seems that in this round trip, i'm ahead by an 
hour. i'm guessing it's got something to do with daylight savings. but 
here's the code that illustrates the problem:
---------------------------
#!/usr/bin/python

import time

thetime = time.time()
timeString = time.ctime(thetime)
print timeString
timeTuple = time.strptime(timeString)
print timeTuple
thetime2 = time.mktime(timeTuple)
timeString2 = time.ctime(thetime2)
print timeString2

-----------------------------
and here's the output i get:

Mon Jun 16 10:45:50 2003
(2003, 6, 16, 10, 45, 50, 0, 167, 0)
Mon Jun 16 11:45:50 2003

----------------------------

i'm on python 2.2.2 on an up2dated rh9.

i've used localtime() etc in place of ctime(). but can't figure this one 
out. it's good up to the tuple returned by strptime(). i would assume 
that both mktime() and  ctime() (i think the culprit here is mktime()) 
would 'do the right thing' without extensive parameter passing for this 
type of default conversions... it this a bug?

thanks,
anoop
aryal at ameritech.net





More information about the Python-list mailing list