time module: round tripping

DavidW Blaschke dwblas at yahoo.com
Mon Jun 16 20:35:16 EDT 2003


Try the programs at this link.  They may be of some
help.  Why not save both forms of time in the text
file and eliminate the conversion?  Every extra step
introduces the possibility of an error at that step. 
If you can avoid it, you can avoid the possible error.

http://www.faqts.com/knowledge_base/index.phtml/fid/583

D.W.

> --- In python-list at yahoogroups.com, Anoop Aryal
> <aryal at a...> wrote:
> > 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 a...
> > 
> > -- 
> >
> http://mail.python.org/mailman/listinfo/python-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list