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);
Call
What 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
Parameter
Description
None
ToFileTime() takes no parameters.
Return Value
Return Value
Description
long
The 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());
}
}
Output
134394858450000000
True
How It Works
Utc input. The value is already UTC, so nothing has to be converted.
Printed number.134394858450000000 counts steps since 1601.
Both methods agree. For Utc, ToFileTime and ToFileTimeUtc give the same number.
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);
}
}
Output
True
How It Works
Local input. The same clock text can mean different moments in different zones.
Convert first.ToUniversalTime moves the clock by the local offset.
Then count.ToFileTimeUtc turns that UTC value into a file time.
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());
}
}
Output
True
10000000
How It Works
To file time and back.FromFileTime returns local time, so it matches the local original.
True. No information was lost in this normal date.
One second later. The second value is exactly one second after the first.
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.