title: How do I get the correct modified datetime of a FAT32 file, regardless of timezone in .NET?
body: <p>Please read this question <strong>fully and carefully</strong> before answering. The answer is not as simple as it might appear.</p>
  
  <p>I am writing a program that needs to keep track of the modified datetime of files, some of which are stored on an external FAT32 drive. The program is being run on various Windows 7 machines.</p>
  
  <p>The problem is the UTC modified datetime changes when the current UTC offset changes. Specifically, when we go from New Zealand Standard Time (UTC+12) to New Zealand Daylight Time (UTC+13) and back again. That is not a typo - the <strong>UTC</strong> modified datetime changes. It shouldn't, that is kind of the point of UTC, but it does. This appears to be a limitation of the FAT32 file system - files on NTFS work fine.</p>
  
  <pre><code>Console.WriteLine(DateTime.Now.ToString() + (DateTime.Now.IsDaylightSavingTime() ? " Daylight" : " Standard"));
  Console.WriteLine(new FileInfo(args[0]).LastWriteTimeUtc.ToString("yyyyMMdd HH mmss"));
  </code></pre>
  
  <p>System timezone is New Zealand and the system date is 9 April 2012 which is New Zealand Standard Time.</p>
  
  <pre><code>C:\Dev\UtcModifiedDatetime\bin\Debug&gt;UtcModifiedDatetime.exe M:\Test1\Test.txt
  2012-04-09 3:53:46 pm Standard
  20120409 03 5316
  </code></pre>
  
  <p>Now set the system date to 1 March 2012 which is New Zealand Daylight Time. Note that I have renamed the directory that contains the test file. This is important because otherwise <strong>Windows will cache the modified datetime</strong> of the file. I wasted a lot of time before I figured that out.</p>
  
  <pre><code>C:\Dev\UtcModifiedDatetime\bin\Debug&gt;UtcModifiedDatetime.exe M:\Test2\Test.txt
  2012-03-01 3:54:13 pm Daylight
  20120409 02 5316
  </code></pre>
  
  <p>Now set the system date back to 9 April 2012 and change the timezone to Adelaide (UTC+09:30).</p>
  
  <pre><code>C:\Dev\UtcModifiedDatetime\bin\Debug&gt;UtcModifiedDatetime.exe M:\Test3\Test.txt
  2012-04-09 1:27:21 pm Standard
  20120409 06 2316
  </code></pre>
  
  <p>So how can I get the correct modified datetime? I could try and figure out if the file is on a FAT32 file system and if it is daylight saving time make a one hour adjustment, but even if I could get that to work it would be a horrible ugly hack. Will using a low level system call work (I suspect not because the problem seems to be at the OS level)? Can I change the timezone of the process, without changing it on the whole machine? Is there any other way?</p>