可能重复:
如何从 C# 中的文件中获取修改日期
您如何使用 C# 读取文件的创建/上次修改时间戳?
来自:http ://www.csharp-examples.net/file-creation-modification-time/
// local times
DateTime creationTime = File.GetCreationTime(@"c:\file.txt");
DateTime lastWriteTime = File.GetLastWriteTime(@"c:\file.txt");
DateTime lastAccessTime = File.GetLastAccessTime(@"c:\file.txt");
// UTC times
DateTime creationTimeUtc = File.GetCreationTimeUtc(@"c:\file.txt");
DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(@"c:\file.txt");
DateTime lastAccessTimeUtc = File.GetLastAccessTimeUtc(@"c:\file.txt");
// write file last modification time (local / UTC)
Console.WriteLine(lastWriteTime); // 9/30/2007 2:16:04 PM
Console.WriteLine(lastWriteTimeUtc); // 9/30/2007 6:16:04 PM
var info = new FileInfo(@"C:\thefile.txt");
var created = info.CreationTime;
var modified = info.LastWriteTime;
using System;
using System.IO;
namespace getLastTimeStamp
{
class Program
{
static void Main(string[] args)
{
FileInfo info = new FileInfo(@"C:\temp\getLastTimeStamp\Program.cs");
Console.WriteLine(info.CreationTime.ToString());
Console.WriteLine(info.LastWriteTime.ToString());
Console.ReadLine();
}
}
}