Solved

Problem with daylight saving time and file modification time

Posted on 2009-05-11
22
648 Views
Last Modified: 2012-06-27
One of the biggest flaws in Microsoft Windows is the fact that the modification time of files changes
when the daylight saving time becomes effective.
This happens ONLY for NTFS file systems, NOT for FAT-oriented systems.
Some of my JAVA applications check if a file has changed by comparing the modification time to a list
kept in a file.
Other JAVA applications compare the modification time of files from disk files to (e.g.) USB stick files.
As almost all USB sticks are FAT-formatted, I'm in trouble 2ce a year.

What to do?
One solution is to format all USB sticks to NTFS and keep an eye on the date.
Another solution is to keep track of file systems (FAT does not store milliseconds or even odd seconds),
but then still half of the year an offset must be added to the FAT-times.

1) how do I get the daylight saving time offset?
2) is there a better solution to this problem?
;JOOP!
0
Comment
Question by:sciuriware
  • 10
  • 9
  • 3
22 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 24361862
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24361942
As I seem unable to format a USB stick to NTFS,
any idea how to deal with the files on FAT?

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24361953
Joop, that's not really correct. The problem afaics is not with ntfs, but with client software that doesn't interpret the timestamps as UTC, which they are. IOW they only appear to have shifted when you *don't* print your dates using a UTC timezone. If you use UTC throughout, you should be fine

http://support.microsoft.com/kb/158588
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 92

Expert Comment

by:objects
ID: 24361968
We try to use GMT wherenever possible, makes life so much easier.
Not sure if possible in your case

0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362149
CEHJ, that 'client software' is: Windows Explorer, TotalCommander and my JAVA
applications.

As I handle the raw

               long File.lastModified()

 I don't see how to I could go wrong with timezones.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362170
>>
As I handle the raw

               long File.lastModified()

 I don't see how to I could go wrong with timezones.
>>

You could *appear* to go wrong if you printed that date with anything other than a UTC tz set
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362173
(Try it with and without to see the difference)
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362307
You just don't get it: I DO NOT PRINT any date or time!

I compare file modification times to decide if a file must be updated
and I record only as raw longs in my list files.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362340
>>I DO NOT PRINT any date or time!

OK - well that's different. But i bet the other two pieces of software you mentioned do:

>>that 'client software' is: Windows Explorer, TotalCommander ...

and they will probably print the date per your system time zone, which i'll bet is *not* UTC or non-DST GMT

I'll think of a test that can be done for your Java app. btw what *is* your time zone?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362350
(Naturally i use the word 'print' loosely, as a synonym for 'display')
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362398
Any way, on UNIX I always get the UTC if I retrieve the .mtime of a file.
There is no difference between C or JAVA.

On MSWindows+NTFS I always get a "time-zoned" modification time, in C++ and in JAVA.
For some reason the raw .lastModified (JAVA) and .mtime (C++) change overnight
when DST switches on or off.
The same happens when I travel to Asia and set the time zone accordingly.
Of course I could switch off DST correction on my PC, but I don't like that.

;JOOP!
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362408
>>> But i bet the other two pieces of software you mentioned do ...

Still the question is not answered: why do they both report differently for FAT and NTFS?

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362451
>>Still the question is not answered: why do they both report differently for FAT and NTFS?

"The FAT file system records times on disk in local time."

( http://msdn.microsoft.com/en-us/library/ms724290(VS.85).aspx )

Is that all clear now?
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362492
Interesting article.
Well, as it seems impossible to get at the UTC timestamp of a file in JAVA I can not solve this problem in JAVA.
Right?

;JOOP!
0
 
LVL 92

Expert Comment

by:objects
ID: 24362534
I'm not aware of a solution, windows can be a real pain sometimes.

0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362552
It is!
I must format all my USB ware to NTFS to make the problem simpler, but I can't.

I'm going to repost this question in the XP area.
Thanks anyway.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362561
>>Well, as it seems impossible to get at the UTC timestamp of a file in JAVA I can not solve this problem in JAVA. Right?

Are you saying that Java changes the time (ntfs times *are* UTC)? (I can't experiment as i have no ntfs volume to hand)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362567
Joop how on earth does that 'accepted answer' answer the question?
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362672
Because it enables me to solve the problem, as soon as I get rid of all those FAT sticks.
Then I simply 'compute' the 'UTC' for any file, which should no longer differ between
January and June.

B.t.w.: think of the following situation with FAT involved:

On 12th of May I create a file at 10:00 on NTFS and record its UTC as 08:00,
then I copy it to FAT, where it will have 10:00 as a timestamp, but must be recorded
as 09:00, because in November the file on NTFS shows 09:00, corrected to 08:00,
but on the FAT it still shows as 10:00.

I just gave up. Stupid NTFS.

P.S.: I just must record all file times, or I must browse all the file system any time
I want to check or backup.

;JOOP!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24362703
>>Stupid NTFS.

It's actually FAT that's stupid: you could only know the correct timestamp is you knew where(!) it was created ;-)
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24362950
OK, how about: both are stupid, only UNIX filesystems make sense.
;JOOP!
0
 
LVL 24

Author Comment

by:sciuriware
ID: 24366509
OK, formatting a USB stick right away is not possible without changing global XP settings,

but the MSDOS command                       convert H:/FS:NTFS
 works very fast.

Bye.

;JOOP!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 42
jsp login check 12 32
Short video clip to play (loop) in email 2 16
Windows Restrict installation 11 19
Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This video teaches viewers about errors in exception handling.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question