file date/time on windows

MRAB google at mrabarnett.plus.com
Wed Jan 28 18:32:01 EST 2009


m.banaouas wrote:
> thanks,
> someone gave me the solution:
> simply call time.localtime(...) instead of time.gmtime(...)
> 
> The explorer file time is what I need because it's the only file date visible
> for most of users. So localtime is perfect for me.
> We are talking about the same file stored in a shared lan-computer-folder.
> I gess that if computers of those users are in different timezones, they could
> see different file date ?
> 
> 
The filetime is stored as UTC and is converted to local time only for 
display. (Actually, that might apply only to NTFS.)

There's also the idiosyncrasy that the filetime, when converted to local 
time, will have 1 added to the hour during DST, irrespective of whether 
the filetime itself was during DST, so a file that was modified at 09:00 
on 1 January will appear to have been modified at 10:00 if viewed during 
June, and a file that was modified at 09:00 on 1 June will appear to 
have been modified at 08:00 if viewed during non-DST!

> MRAB a écrit :
>> m.banaouas wrote:
>>> hi,
>>>
>>> I noticed recently that the value of file date/time I get with python:
>>> time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime))
>>> is forwarding by one hour the real file date/time.
>>>
>>> Example:
>>> file A.txt: 2009-01-18 16:13
>>> returned valeur:  2009-01-28 15:13
>>>
>>> Is there a simple way to get it work correctely  (other than adding
>>> always 1
>>> hour ...) ?
>>>
>> time.gmtime(), as the name suggests, returns GMT (UTC).
>>
>> From your email address I presume you're in France, which is GMT+1.
>>
>> Windows Explorer shows the file time in local time, which for you is
>> currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list