-1

So I have a file..

var myFile = C:\docs\MyFile.pptx

and when I noticed that

FileInfo fi = new FileInfo(myfile);
var lastModified = fi.LastWriteTime;

and

var lastModified = File.GetLastWriteTimeUtc(myFile);

are returning different values. Why is this? The FileInfo value corresponds to the one displayed in Windows Explorer Date Modified column. Why do they differ? I would have expected them to would return exactly the same value.

JKennedy
  • 18,150
  • 17
  • 114
  • 198

1 Answers1

2

I've actually checked the code in Reflector and they both do the exact same thing, i.e:

return DateTime.FromFileTimeUtc((long) data.ftLastWriteTimeHigh << 32 | (long) data.ftLastWriteTimeLow);

vs

return DateTime.FromFileTimeUtc((long) this._data.ftLastWriteTimeHigh << 32 | (long) this._data.ftLastWriteTimeLow);

I've also tested it and dates are the same. You must have accidentally compared Utc with a non-Utc function.

bokibeg
  • 2,081
  • 16
  • 23