Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức DateTime.FromFileTimeUtc() trong C#

Phương thức DateTime.FromFileTimeUtc() trong C# chuyển đổi thời gian file Windows được chỉ định thành thời gian UTC tương đương.

Cú pháp

public static DateTime FromFileTimeUtc(long time);

Tham số time là thời gian file Windows tính bằng ticks (100-nanosecond ticks).

Ví dụ 1

using System;
public class Demo
{
    public static void Main()
    {
        DateTime d1 = DateTime.FromFileTimeUtc(6500000000000);
        System.Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);
    }
}

Đầu ra

DateTime = 08 January 1601, 12:33:20

Ví dụ 2

using System;
public class Demo
{
    public static void Main()
    {
        DateTime d1 = DateTime.FromFileTimeUtc(0);
        DateTime d2 = DateTime.FromFileTimeUtc(850000000000000);
        Console.WriteLine("DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);
        Console.WriteLine("New DateTime = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d2);
    }
}

Đầu ra

DateTime = 01 January 1601, 12:00:00
New DateTime = 11 September 1603, 07:06:40