file date/time on windows

M

m.banaouas

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 ...) ?

thanks
 
M

MRAB

m.banaouas said:
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.
 
M

m.banaouas

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 ?


MRAB a écrit :
 
M

MRAB

m.banaouas said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,377
Latest member
Zebacus

Latest Threads

Top