C# DateTime FromFileTime() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, a Windows file time is the number of 100-nanosecond steps since January 1, 1601 (UTC). DateTime.FromFileTime reads that number and returns a DateTime in the computer's local time zone.

Use FromFileTimeUtc when you want a UTC result instead. File times appear in Windows APIs, file properties, and some network formats.

This is a static member of System.DateTime. You call it with the type name, such as DateTime.FromFileTime(...). DateTime holds a date and time of day with a Kind of Utc, Local, or Unspecified.

Syntax

Call it with the type name and a long file time.

C#
long ft = 134394858450000000;                 // 2026-11-18 14:30:45 UTC
DateTime local = DateTime.FromFileTime(ft);   // Kind: Local
DateTime utc = DateTime.FromFileTimeUtc(ft);  // Kind: Utc
CallWhat it does
DateTime.FromFileTime(ft)File time to local time.
DateTime.FromFileTimeUtc(ft)The same number to UTC.
dt.ToFileTime()The opposite direction.

Because the result depends on the zone of the computer, the examples below print the Kind and compare with the UTC version instead of printing the local clock time.

Library declarations
C#
public static DateTime FromFileTime(long fileTime);

Parameters

ParameterDescription
fileTimeRequired. A Windows file time: ticks since January 1, 1601 UTC. Must not be negative.

Return Value

Return ValueDescription
DateTimeThe date and time in the local zone, with Kind.Local.

C# Examples

Example 1 — Two Kinds from One Number

Convert one file time two ways and print the Kind and the UTC clock.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        long ft = 134394858450000000;
        DateTime local = DateTime.FromFileTime(ft);
        DateTime utc = DateTime.FromFileTimeUtc(ft);
        Console.WriteLine(local.Kind);
        Console.WriteLine(utc.Kind);
        Console.WriteLine(utc.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
    }
}

How It Works

  1. One number. 134394858450000000 is a file time for November 18, 2026, 14:30:45 UTC.
  2. FromFileTime. It returns local time, so its Kind is Local.
  3. FromFileTimeUtc. It returns UTC, so its Kind is Utc.
  4. Stable text. Only the UTC value is printed as a clock, because it is the same on every computer.

Example 2 — Back and Forth

Convert the local result back to UTC and back to a file time.

C#
using System;

class Program {
    static void Main() {
        long ft = 134394858450000000;
        DateTime local = DateTime.FromFileTime(ft);
        Console.WriteLine(local.ToUniversalTime() == DateTime.FromFileTimeUtc(ft));
        Console.WriteLine(local.ToFileTime() == ft);
    }
}

How It Works

  1. Local value. local holds the same moment as the UTC value, shown on the local clock.
  2. ToUniversalTime. Shifting it back gives the UTC version, so the first line is True.
  3. ToFileTime. Converting the local value back returns the original number.
  4. Second line True. The round trip loses nothing for this normal date.

Example 3 — The Local Shift

Prove that local time differs from UTC by exactly the zone offset.

C#
using System;

class Program {
    static void Main() {
        long ft = 134394858450000000;
        DateTime local = DateTime.FromFileTime(ft);
        DateTime utc = DateTime.FromFileTimeUtc(ft);
        TimeSpan shift = local - utc;
        Console.WriteLine(shift == TimeZoneInfo.Local.GetUtcOffset(utc));
    }
}

How It Works

  1. Two clocks. One is local and one is UTC, built from the same file time.
  2. Subtract them. The TimeSpan is how many hours the local clock is ahead of UTC.
  3. Ask the zone. GetUtcOffset returns the zone's offset for that moment.
  4. Always True. The check holds in every time zone, so the output never changes.

Frequently Asked Questions

It is the number of 100-nanosecond steps since January 1, 1601 (UTC).
FromFileTime returns local time (Kind Local). FromFileTimeUtc returns UTC (Kind Utc).
It throws ArgumentOutOfRangeException.
Use dt.ToFileTime() for local or dt.ToFileTimeUtc() for UTC.
The local clock changes with the computer time zone, so the tutorial prints Kind and checks instead.

Next: FromFileTimeUtc()

Convert a Windows file time number to a DateTime in UTC with System.DateTime.

FromFileTimeUtc() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful