getmtime in 2.5 reports GMT instead of local time

John Machin sjmachin at lexicon.net
Thu May 3 18:50:36 EDT 2007


On May 4, 12:26 am, Josef Dalcolmo <Josef.Dalco... at gmx.net> wrote:
> Hello,
>
> I have tried this only on Windows XP.
>
> in Python 2.4 os.path.getmtime() used to return an integer representing
> the local time.

The docs say "seconds since the epoch". Noting that the epoch is
usually defined with reference to UTC, "local time" is rather
unlikely.

>
> in Python 2.5 os.path.getmtime() reports a float representing the GMT of the
> file's modification time.
>
> Since I could not find any documentation to this behavioural change, I am asking
> here: was this change intentional? Is it going to stay? Windows reports
> the same time for the file as Python 2.4 used to. So I am tempted to
> call this a bug, but wanted some feedback from the developers,
> before filing a bug report.
>
> If you want to test this, make sure your local time differs from GMT,
> then do:
>
> import os, time
> print time.ctime(os.path.getmtime('foo.txt'))
>
> on a file foo.txt, once with Python 2.4 then with Python 2.5,
> and you should see what I mean.

No way, Jose.

C:\junk>\python24\python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, os.path, time; fn = 'hello_u.txt'; print os.stat(fn).st_mtime, os
.path.getmtime(fn)
1178228403 1178228403
>>> import os, os.path, time; fn = 'hello_u.txt'; print time.ctime(os.stat(fn).s
t_mtime), time.ctime(os.path.getmtime(fn))
Fri May 04 07:40:03 2007 Fri May 04 07:40:03 2007
>>> ^Z


C:\junk>\python25\python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, os.path, time; fn = 'hello_u.txt'; print os.stat(fn).st_mtime, os
.path.getmtime(fn)
1178228403.3 1178228403.3
>>> import os, os.path, time; fn = 'hello_u.txt'; print time.ctime(os.stat(fn).s
t_mtime), time.ctime(os.path.getmtime(fn))
Fri May 04 07:40:03 2007 Fri May 04 07:40:03 2007
>>> ^Z

My TZ is 10 hours (plus/minus daylight saving) away from UTC. The
above ctime results are correct AFAICT to plus/minus a few minutes.
The change from integer to float in 2.5 is documented under
os.stat_float_times.




More information about the Python-list mailing list