Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

ดูเวลาสร้างไฟล์ใน C#

ใช้ FileInfo.CreationTime Property ดึงวันเวลาที่ไฟล์ถูกสร้าง

ตัวอย่างโค้ด

using System;
using System.IO;

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");
        DateTime dt = file.CreationTime;
        Console.WriteLine(dt);
    }
}

ผลลัพธ์ (ตัวอย่าง)

9/5/2018 5:20:03 AM

คุณสมบัติที่เกี่ยวข้อง: LastAccessTime, LastWriteTime, CreationTimeUtc (เวลา UTC)