In C#, DateTime.ToFileTimeUtc() returns the Windows file time: the number of 100-nanosecond steps since January 1, 1601 UTC.
A Utc or Unspecified value is counted as is. A Local value is converted to UTC first. The result is the same on every computer for Utc and Unspecified values.
This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.ToFileTimeUtc(...). 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.ToFileTimeUtc(); // 134394858450000000
DateTime back = DateTime.FromFileTimeUtc(ft);
Call
What it does
dt.ToFileTimeUtc()
File time for a UTC (or Unspecified) value.
new DateTime(1601, 1, 1).ToFileTimeUtc()
The smallest valid value: 0.
DateTime.FromFileTimeUtc(ft)
The opposite direction.
Subtract the file time of two dates to get the gap in ticks. Divide by TimeSpan.TicksPerSecond to get seconds.
Library declarations
C#
public long ToFileTimeUtc();
Parameters
Parameter
Description
None
ToFileTimeUtc() 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 — Zero and One Second
Show the file time for the first moment and one second later.
C#
using System;
class Program {
static void Main() {
DateTime first = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime second = first.AddSeconds(1);
Console.WriteLine(first.ToFileTimeUtc());
Console.WriteLine(second.ToFileTimeUtc());
}
}
Output
0
10000000
How It Works
First moment. January 1, 1601 at midnight UTC is the origin, so the number is 0.
One second later.AddSeconds(1) moves one second forward.
10000000. A second is 10,000,000 steps of 100 nanoseconds.
Linear count. The number grows by one for each tick that passes.
Example 2 — Convert and Restore
Convert a 2026 UTC value to a file time and restore it.
C#
using System;
using System.Globalization;
class Program {
static void Main() {
DateTime utc = new DateTime(2026, 11, 18, 14, 30, 45, DateTimeKind.Utc);
long ft = utc.ToFileTimeUtc();
Console.WriteLine(ft);
Console.WriteLine(DateTime.FromFileTimeUtc(ft).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
}
}
Output
134394858450000000
2026-11-18 14:30:45
How It Works
A fixed date. The value is November 18, 2026 at 14:30:45 UTC.
Big number.134394858450000000 is about 1.3 times ten to the 17th power.
Restore.FromFileTimeUtc gives the same date and time back.
Lossless. The round trip keeps every tick of the original value.
Example 3 — Unix Epoch and Before 1601
Show the file time of 1970 and catch a date that is too old.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(new DateTime(1970, 1, 1).ToFileTimeUtc());
try {
new DateTime(1600, 12, 31).ToFileTimeUtc();
} catch (ArgumentOutOfRangeException) {
Console.WriteLine("Before 1601 is not allowed");
}
}
}
Output
116444736000000000
Before 1601 is not allowed
How It Works
Unix epoch. January 1, 1970 is 369 years after 1601.
Unspecified is not shifted. The value is counted as it is, with no local time conversion.
Too early. December 31, 1600 comes before the file-time origin.
Exception.ArgumentOutOfRangeException is caught and a message is printed.
Frequently Asked Questions
A Windows file time for the value, counted from January 1, 1601 UTC.
January 1, 1601. Earlier dates throw ArgumentOutOfRangeException.
No. File time counts 100 ns steps from 1601. Unix time counts seconds from 1970.
Divide by TimeSpan.TicksPerSecond (10,000,000).
ToFileTime treats Unspecified as local and shifts it to UTC first. ToFileTimeUtc counts Unspecified as is.