Convert the specified Windows file time to an equivalent local time in C#


To convert the specified Windows file time to an equivalent local time, the code is as follows −

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      DateTimeOffset offset = DateTimeOffset.FromFileTime(0);
      Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",offset);
   }
}

Output

This will produce the following output −

DateTimeOffset = 01 January 1601, 12:00:00

Example

Let us see another example −

 Live Demo

using System;
public class Demo {
   public static void Main() {
      DateTimeOffset offset = DateTimeOffset.FromFileTime(200000000);
      Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",offset);
   }
}

Output

This will produce the following output −

DateTimeOffset = 01 January 1601, 12:00:20

Updated on: 06-Dec-2019

162 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements