C# 临时目录中使用的File.SetLastWriteTimeUtc

C# 临时目录中使用的File.SetLastWriteTimeUtc,c#,windows,C#,Windows,如果在用户临时目录中应用了File.SetLastWriteTimeUtc,则它将设置为与指定的修改时间不同的1-2秒。在LastWriteTime上,正确应用了以小时为单位的时区差异,但奇怪的是,以秒为单位的时区差异也存在 例如: using System.IO; string tempDir = System.IO.Path.GetTempPath(); // required new last write datetime 2012-12-05 15:50:15 DateTime new

如果在用户临时目录中应用了File.SetLastWriteTimeUtc,则它将设置为与指定的修改时间不同的1-2秒。在LastWriteTime上,正确应用了以小时为单位的时区差异,但奇怪的是,以秒为单位的时区差异也存在

例如:

using System.IO;

string tempDir = System.IO.Path.GetTempPath();
// required new last write datetime 2012-12-05 15:50:15
DateTime newLastWriteTimeUtc = new DateTime(2012, 12, 5, 15, 50, 15, 0);
string testFilePath = Path.Combine(tempDir, "Test.txt");
if (File.Exists(testFilePath))
{
  File.SetLastWriteTimeUtc(testFilePath, newLastWriteTimeUtc);
  FileInfo fInfo = new FileInfo(testFilePath);
  // you get real datetime 2012-12-05 15:50:16
  DateTime lastWriteTimeUtc = fInfo.LastWriteTimeUtc;
}

有人能解释一下这种行为吗?

FAT32文件系统时间戳分辨率为2秒。和你看到的很相配。如果它实际上是NTFS,那么就不信任那种想要干扰文件访问的软件。比如反恶意软件。