DateTimeOffset.ToFileTime() Method in C#


The DateTimeOffset.ToFileTime() method in C# is used to convert the value of the current DateTimeOffset object to a Windows file time. The method returns an Int64 value of the current DateTimeOffset object, expressed as a Windows file time.

Syntax

Following is the syntax −

public long ToFileTime ();

Example

Let us now see an example to implement the DateTimeOffset.ToFileTime() method −

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);
   }
}

Output

This will produce the following output −

DateTimeOffset = 11/10/2019 6:20:10 AM -05:00
DateTimeOffset HashCode = -92293937
Windows file time = 132178584100000000

Example

Let us now see another example to implement the DateTimeOffset.ToFileTime() method −

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);
   }
}

Output

This will produce the following output −

DateTimeOffset = 10/16/2019 11:16:47 AM +00:00
Windows file time = 132156982075593442

Updated on: 12-Nov-2019

32 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements