469,282 Members | 1,921 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

getmtime in 2.5 reports GMT instead of local time

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.

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.

- Josef
May 3 '07 #1
1 2910
On May 4, 12:26 am, Josef Dalcolmo <Josef.Dalco...@gmx.netwrote:
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.

May 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Qvx | last post: by
5 posts views Thread by Jorg Rødsjø | last post: by
16 posts views Thread by Josef Dalcolmo | last post: by
3 posts views Thread by junchi.tang | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.