time module: round tripping
dwblas at yahoo.com
Tue Jun 17 02:35:16 CEST 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.
> --- 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
> > appriciate it if you could point me to the right
> > i had needed to do some time manipulation -- take
> the unix time
> > convert it to localtime (human readable format),
> save it to a text
> > later, read it from the text file, convert it back
> to unix time
> > 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.
> > 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
> > out. it's good up to the tuple returned by
> strptime(). i would
> > that both mktime() and ctime() (i think the
> culprit here is
> > would 'do the right thing' without extensive
> parameter passing for
> > type of default conversions... it this a bug?
> > thanks,
> > anoop
> > aryal at a...
> > --
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
More information about the Python-list