C# DateTime ToFileTimeUtc() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

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);
CallWhat 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

ParameterDescription
NoneToFileTimeUtc() takes no parameters.

Return Value

Return ValueDescription
longThe 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());
    }
}

How It Works

  1. First moment. January 1, 1601 at midnight UTC is the origin, so the number is 0.
  2. One second later. AddSeconds(1) moves one second forward.
  3. 10000000. A second is 10,000,000 steps of 100 nanoseconds.
  4. 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));
    }
}

How It Works

  1. A fixed date. The value is November 18, 2026 at 14:30:45 UTC.
  2. Big number. 134394858450000000 is about 1.3 times ten to the 17th power.
  3. Restore. FromFileTimeUtc gives the same date and time back.
  4. 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");
        }
    }
}

How It Works

  1. Unix epoch. January 1, 1970 is 369 years after 1601.
  2. Unspecified is not shifted. The value is counted as it is, with no local time conversion.
  3. Too early. December 31, 1600 comes before the file-time origin.
  4. 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.

Next: ToLocalTime()

Convert a UTC DateTime to local time; the result has Kind Local with System.DateTime.

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

7 people found this page helpful