Solved

Problem with daylight saving time and file modification time

Posted on 2009-05-11
22
662 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

734 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