使用 C# 读取文件的最后修改时间戳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12484515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:24:55 来源:igfitidea点击:
Read created last modified time-stamp of a file using C#
提问by Abhijeet
Possible Duplicate:
How to get Modified date from file in c#
可能的重复:
如何从 C# 中的文件中获取修改日期
How do you, Read created / last modified time-stamp of a file, using C#?
您如何使用 C# 读取文件的创建/上次修改时间戳?
采纳答案by Chimera
From: http://www.csharp-examples.net/file-creation-modification-time/
来自: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
回答by moribvndvs
See System.IO.FileInfo.
var info = new FileInfo(@"C:\thefile.txt");
var created = info.CreationTime;
var modified = info.LastWriteTime;
回答by Gustavo F
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();
}
}
}

