DateTime.ToFileTimeUtc 方法

定义

将当前 DateTime 对象的值转换为 Windows 文件时间。Converts the value of the current DateTime object to a Windows file time.

public:
 long ToFileTimeUtc();
public long ToFileTimeUtc ();
member this.ToFileTimeUtc : unit -> int64
Public Function ToFileTimeUtc () As Long

返回

表示为 Windows 文件时间的当前 DateTime 对象的值。The value of the current DateTime object expressed as a Windows file time.

异常

所生成的文件时间将表示公元 1601 年 1 月 1 日午夜 12:00 之前的日期和时间。The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC。UTC.

注解

Windows 文件时间是一个64位的值,它表示自公元1900年1月 1601 1 日午夜12:00 之后经过的100纳秒间隔数A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. 公元协调世界时(UTC)。(C.E.) Coordinated Universal Time (UTC). 当应用程序创建、访问或写入到文件时,Windows 将使用文件时间来记录。Windows uses a file time to record when an application creates, accesses, or writes to a file.

ToFileTimeUtc 方法使用 Kind 属性来确定当前 DateTime 对象是否为本地时间、UTC 时间或被视为 UTC 时间的未指定时间类型。The ToFileTimeUtc method uses the Kind property to determine whether the current DateTime object is a local time, a UTC time, or an unspecified kind of time which is treated as a UTC time. 如果它是本地时间,则会在执行到 Windows 文件时间的转换之前将时间转换为 UTC。If it is a local time, it converts the time to UTC before performing the conversion to a Windows file time.

调用方说明

ToFileTimeUtc() 方法有时用于将本地时间转换为 UTC,然后通过调用 FromFileTimeUtc(Int64) 方法后跟 ToLocalTime() 方法来还原该时间。The ToFileTimeUtc() method is sometimes used to convert a local time to UTC, and subsequently to restore it by calling the FromFileTimeUtc(Int64) method followed by the ToLocalTime() method. 但是,如果原始时间表示本地时区中的无效时间,则两个本地时间值将不相等。However, if the original time represents an invalid time in the local time zone, the two local time values will not be equal. 有关其他信息,请参阅 ToLocalTime() 方法。For additional information, see the ToLocalTime() method.

适用于

另请参阅