C#中的DateTimeOffset.ToFileTime()方法
C#中的DateTimeOffset.ToFileTime()方法用于将当前DateTimeOffset对象的值转换为Windows文件时间。该方法返回当前DateTimeOffset对象的Int64值,表示为Windows文件时间。
语法
以下是语法-
public long ToFileTime ();
示例
现在让我们看一个实现DateTimeOffset.ToFileTime()方法的示例-
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset1 = new DateTimeOffset(2019, 11, 10, 6, 20, 10, new TimeSpan(-5, 0, 0)); Console.WriteLine("DateTimeOffset = {0}", dateTimeOffset1); int hash = dateTimeOffset1.GetHashCode(); long res = dateTimeOffset1.ToFileTime(); Console.WriteLine("DateTimeOffset HashCode = {0}", hash); Console.WriteLine("Windows file time = {0}", res); } }
输出结果
这将产生以下输出-
DateTimeOffset = 11/10/2019 6:20:10 AM -05:00 DateTimeOffset HashCode = -92293937 Windows file time = 132178584100000000
示例
现在让我们来看另一个实现DateTimeOffset.ToFileTime()方法的示例-
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset1 = DateTimeOffset.Now; Console.WriteLine("DateTimeOffset = {0}", dateTimeOffset1); long res = dateTimeOffset1.ToFileTime(); Console.WriteLine("Windows file time = {0}", res); } }
输出结果
这将产生以下输出-
DateTimeOffset = 10/16/2019 11:16:47 AM +00:00 Windows file time = 132156982075593442