#306 os.path.getmtime timezone issue

open-duplicate
Jukka Laurila
other (34)
5
2008-08-22
2008-08-22
Josh Rooke-Ley
No

I been trying to get the file modification time on a file but it looks like the getmtime is applying the timezone offset on a time that is already in UTC time. Here is some sample code:

Python 2.2.2 (#0, Jun 10 2008, 15:05:00) [C] on symbian_s60
Type "copyright", "credits" or "license" for more information.
Type "commands" to see the commands available in this simple line editor.
>>>
>>> import os,time
>>>
>>> file_path = 'C:\\test_filemod.txt'
>>> test_file = open(file_path,'w')
>>> test_file.write("foobar")
>>> test_file.close()
>>> test_file_mod = os.path.getmtime(file_path)
>>> test_file_mod
1219446036
>>> test_now = time.time()
>>> test_now - test_file_mod
-14400.0
>>>

I am running this code on a nokia n95 with EDT set as the timezone (time.altzone=14400) so it looks like getmtime is getting a time that is exactly off by my timezone.

If I run the same code on my desktop machine it looks like this:

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os,time
>>>
>>> file_path = '/tmp/foo.txt'
>>> test_file = open(file_path,'w')
>>> test_file.write("foobar")
>>> test_file.close()
>>> test_file_mod = os.path.getmtime(file_path)
>>> test_file_mod
1219431742.0
>>> test_now = time.time()
>>> test_now - test_file_mod
0.66671490669250488
>>>

I am running this on a 3Gig N95

Discussion

  • Josh Rooke-Ley
    Josh Rooke-Ley
    2008-08-22

    Logged In: YES
    user_id=2023748
    Originator: YES

    This looks like its the same as #2000698.

     
  • Josh Rooke-Ley
    Josh Rooke-Ley
    2008-08-22

    • status: open --> open-duplicate