獲取 C# 中檔案建立的時間
如要在 C# 中獲取檔案建立的時間,請使用 CreationTime() 方法。
為此,使用 FileInfo 和 DateTime 類,建立每個類的物件 −
FileInfo file = new FileInfo("new.txt");
DateTime dt = file.CreationTime;讓我們看看完整的程式碼 −
示例
using System.IO;
using System;
public class Program {
public static void Main() {
using (StreamWriter sw = new StreamWriter("qa.txt")) {
sw.WriteLine("Questions and Answers!");
}
FileInfo file = new FileInfo("qa.txt");
// file creation time
DateTime dt = file.CreationTime;
Console.WriteLine(dt);
}
}輸出
9/5/2018 5:20:03 AM
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP