DateTime.ToFileTimeUtc() Method in C#


The DateTime.ToFileTimeUtc() method in C# is used to convert the value of the current DateTime object to a Windows file time.

Syntax

Following is the syntax −

public long ToFileTimeUtc ();

Example

Let us now see an example to implement the DateTime.ToFileTimeUtc() method −

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.ToFileTimeUtc();
      Console.WriteLine("Windows file time (Utc) = {0}", res);
   }
}

Output

This will produce the following output −

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

Example

Let us now see another example to implement the DateTime.ToFileTimeUtc() method −

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

Output

This will produce the following output −

Date = 10/16/2019 8:25:58 AM
Windows file time (Utc) = 132156879583999032

Updated on: 21-Apr-2020

138 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements