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

เมธอด DateTime.ToFileTime() ใน C#

เมธอด DateTime.ToFileTime() ใน C# ใช้แปลงค่าของออบเจ็กต์ DateTime ปัจจุบันเป็นเวลาไฟล์ Windows

ไวยากรณ์

public long ToFileTime ();

ตัวอย่าง

ตัวอย่างที่ 1: แปลง DateTime.Now เป็นเวลาไฟล์ Windows

using System; 
public class Demo { 
    public static void Main() { 
        DateTime d = DateTime.Now; 
        Console.WriteLine("Date = {0}", d); 
        long res = d.ToFileTime(); 
        Console.WriteLine("Windows file time = {0}", res); 
    } 
}

ผลลัพธ์

Date = 10/16/2019 8:17:26 AM 
Windows file time = 132156874462559390

ตัวอย่างเพิ่มเติม

ตัวอย่างที่ 2: แปลงวันที่เฉพาะเจาะจงเป็นเวลาไฟล์ Windows

using System; 
public class Demo { 
    public static void Main() { 
        DateTime d = new DateTime(2019, 05, 10, 6, 10, 25); 
        Console.WriteLine("Date = {0}", d); 
        long res = d.ToFileTime(); 
        Console.WriteLine("Windows file time = {0}", res); 
    } 
}

ผลลัพธ์

Date = 5/10/2019 6:10:25 AM 
Windows file time = 132019422250000000