time/strptime/mktime/localtime
Oleg Broytmann
phd at phd.russ.ru
Fri Nov 12 06:01:20 EST 1999
Hi!
Thanks for replying.
On Fri, 12 Nov 1999, M.-A. Lemburg wrote:
> > The following program prints "1999-09-21 21:44:33" on Linux and
> > "1999-09-21 22:44:33" on Solaris (1 hour offset).
> >
> > Is it a problem with my config? libs? python? Timezone is Europe/Moscow,
> > set (I think) correctly on both systems.
> >
> > #! /usr/local/bin/python -O
> >
> > import time
> >
> > t = time.strptime("1999-09-21 21:44:33", "%Y-%m-%d %T")
> > m = time.mktime(t)
> > print time.strftime("%Y-%m-%d %T", time.localtime(m))
>
> Could be that one of those sets the DST flag to 0 while
> the other sets it to 1... please provide the output of
> time.strptime() for both machines.
print time.strptime("1999-09-21 21:44:33", "%Y-%m-%d %T")
Linux: (1999, 9, 21, 21, 44, 33, 6, 1, 0)
Solaris: (1999, 9, 21, 21, 44, 33, 6, 1, 0)
No difference. Anyway, I think you are near to be right, as I found
there are some dates that converted back and forth correctly, without 1
hour offset.
t = time.strptime("1999-10-31 14:50:16", "%Y-%m-%d %T")
m = time.mktime(t)
print time.strftime("%Y-%m-%d %T", time.localtime(m))
prints "1999-10-31 14:50:16", what is Ok...
Seems the error is relative to DST. May be I have incorrect timezone
definition on Solaris...
Oleg.
----
Oleg Broytmann Foundation for Effective Policies phd at phd.russ.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list
mailing list