Monday, October 12, 2009

Why does a file on a Windows machine have different timestamps on different Windows machines?

I have a program (which runs on a Windows machine) that gets a list of files and their corresponding timestamps from a remote Windows machine.

On the 4th of Oct (the day when Daylight savings triggered of a 1.59am to 3am time change in Melbourne, Australia), my program returned a null value when retrieving the last modified timestamp of a file that was created at 1.21am that day.

What puzzled me was that although the file was created at 1.21am (which was recorded within the contents of the file), the last modified timestamp was 2.21am. When I uploaded this file across to a machine that had the Windows option "Automatically Adjust for Daylight Saving Time" turned off, it had a last modified time of 1.21am.

After reading up on http://www.peterdonis.net/computers/computersarticle3.html and http://support.microsoft.com/kb/129574 , I finally realised why the last modified timestamp of the file on a Windows machine was different to the timestamp when it was actually created:

On Windows, if you are in a location that observes DST (Daylight Savings Time) and the DST time change kicks in, the timestamps on all files on the Windows NT file system (NTFS) are shifted by an hour. Even the files that were created BEFORE the daylight saving time change are shifted. So basically, the timestamps of ALL files created ANYTIME before 4/10/2009 1.59am will have one hour added to it.

As stated on the Windows Help and Support page, "All times displayed in Windows NT for event log events and files on NTFS partitions are computed as offsets to Greenwich Mean Time (GMT). When you set the time on your system, you are setting the value for GMT. When you select your local time zone for the system, the appropriate number of hours are added or subtracted to the stored GMT value. This adjusted time is displayed. When "Automatically Adjust for Daylight Saving Time" is selected, an additional hour is added to GMT during daylight savings time (the first Sunday in April through the last Sunday in October)." In other words, manually changing the system time does not affect file timestamps but when the local time zone is changed, all file timestamps will be adjusted to display the new zone time.

No comments:

Post a Comment

Thank you for your comment.