C# DateTime ToFileTime() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.ToFileTime() returns a long Windows file time: the number of 100-nanosecond steps since January 1, 1601 (UTC).

The method first converts the value to UTC (a Local or Unspecified value is treated as local time) and then counts the steps. A Utc value is not shifted.

This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.ToFileTime(...). DateTime is a struct, so every value is copied and never changed in place.

Syntax

Call it on a DateTime. It takes no arguments.

C#
DateTime utc = new DateTime(2026, 11, 18, 14, 30, 45, DateTimeKind.Utc);
long ft = utc.ToFileTime();       // 134394858450000000
DateTime local = DateTime.FromFileTime(ft);
CallWhat it does
dt.ToFileTime()Local time to file time (via UTC).
dt.ToFileTimeUtc()File time without a local conversion.
DateTime.FromFileTime(ft)The opposite direction.

For a Local value the result depends on the zone of the computer. Dates before January 1, 1601 are not valid and throw ArgumentOutOfRangeException.

Library declarations
C#
public long ToFileTime();

Parameters

ParameterDescription
NoneToFileTime() takes no parameters.

Return Value

Return ValueDescription
longThe Windows file time: 100-nanosecond steps since January 1, 1601 UTC.

C# Examples

Example 1 — Utc Needs No Shift

Show that a Utc value gives the same number from both file time methods.

C#
using System;

class Program {
    static void Main() {
        DateTime utc = new DateTime(2026, 11, 18, 14, 30, 45, DateTimeKind.Utc);
        Console.WriteLine(utc.ToFileTime());
        Console.WriteLine(utc.ToFileTime() == utc.ToFileTimeUtc());
    }
}

How It Works

  1. Utc input. The value is already UTC, so nothing has to be converted.
  2. Printed number. 134394858450000000 counts steps since 1601.
  3. Both methods agree. For Utc, ToFileTime and ToFileTimeUtc give the same number.
  4. Prints True. The difference appears only for Local and Unspecified values.

Example 2 — Local Goes Through UTC

Show that a Local value is converted to UTC before counting.

C#
using System;

class Program {
    static void Main() {
        DateTime local = new DateTime(2026, 11, 18, 14, 30, 45, DateTimeKind.Local);
        long viaMethod = local.ToFileTime();
        long viaUtc = local.ToUniversalTime().ToFileTimeUtc();
        Console.WriteLine(viaMethod == viaUtc);
    }
}

How It Works

  1. Local input. The same clock text can mean different moments in different zones.
  2. Convert first. ToUniversalTime moves the clock by the local offset.
  3. Then count. ToFileTimeUtc turns that UTC value into a file time.
  4. Same answer. ToFileTime does both steps in one call, so the line prints True.

Example 3 — Back and One Second

Round trip a Local value and measure a one-second step.

C#
using System;

class Program {
    static void Main() {
        DateTime local = new DateTime(2026, 11, 18, 14, 30, 45, DateTimeKind.Local);
        Console.WriteLine(DateTime.FromFileTime(local.ToFileTime()) == local);

        DateTime utc = new DateTime(2026, 11, 18, 14, 30, 45, DateTimeKind.Utc);
        Console.WriteLine(utc.AddSeconds(1).ToFileTime() - utc.ToFileTime());
    }
}

How It Works

  1. To file time and back. FromFileTime returns local time, so it matches the local original.
  2. True. No information was lost in this normal date.
  3. One second later. The second value is exactly one second after the first.
  4. 10000000. A file time counts ticks, and one second is 10,000,000 ticks.

Frequently Asked Questions

The Windows file time: 100-nanosecond steps since January 1, 1601 UTC.
ToFileTime treats Local and Unspecified values as local time and converts them to UTC first. ToFileTimeUtc does not shift Unspecified.
It throws ArgumentOutOfRangeException.
Use DateTime.FromFileTime(ft) for local time or DateTime.FromFileTimeUtc(ft) for UTC.
10,000,000, the same as the number of ticks per second.

Next: ToFileTimeUtc()

Convert a DateTime to a Windows file time number without a local-time shift for Unspecified values with System.DateTime.

ToFileTimeUtc() 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.

15 people found this page helpful