Để biết thời gian tạo tệp trong C #, hãy sử dụng phương thức CreationTime ().
Đối với điều này, hãy sử dụng các lớp FileInfo cũng như DateTime. Tạo một đối tượng của mỗi -
FileInfo file = new FileInfo("new.txt");
DateTime dt = file.CreationTime; Hãy cho chúng tôi xem mã hoàn chỉnh -
Ví dụ
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);
}
} Đầu ra
9/5/2018 5:20:03 AM