How to convert .NET DateTime ticks to a Unix timestamp and back

By TechCompare · Updated · How we check

Subtract 621355968000000000, the tick count of January 1, 1970, then divide by 10,000,000 for Unix seconds or by 10,000 for milliseconds. That only works when the ticks came from a UTC DateTime.

A .NET tick is 100 nanoseconds, and DateTime.Ticks counts them from midnight on January 1 of the year 1. The example here, 639161082000000000, is June 3, 2026 at 18:30:00 UTC, which is Unix time 1780511400. Getting from one to the other takes a subtraction and a division.

Unix timestamp
1,780,511,400
Seconds since epoch
ISO 8601
2026-06-03T18:30:00.000Z
Wed, 03 Jun 2026 18:30:00 GMT
Category
Windows and .NET
Timestamp knowledge base

How this is calculated

Microsoft's docs define the value as "the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 in the Gregorian calendar". Ticks skip leap seconds, the same as Unix time, so the gap between the two counts never changes:

Ticks to Unix seconds
(639161082000000000 - 621355968000000000) / 10000000 = 1780511400

In C#, DateTime.UnixEpoch holds that starting point, from .NET Core 2.1 on, so you don't have to type the constant. DateTimeOffset converts in both directions:

C#
long ticks = 639161082000000000;
long seconds = (ticks - DateTime.UnixEpoch.Ticks) / TimeSpan.TicksPerSecond; // 1780511400
var date = new DateTime(ticks, DateTimeKind.Utc);
long viaOffset = new DateTimeOffset(date).ToUnixTimeSeconds(); // 1780511400
long back = DateTimeOffset.FromUnixTimeSeconds(1780511400).UtcTicks; // 639161082000000000

A tick count doesn't say which clock it came from. The same docs say a Local DateTime's ticks count "in the local time as specified by the current time zone setting", and a Utc one's count in UTC. The formula above assumes UTC.

Before 1970, the two C# routes can disagree. Integer division in C# rounds toward zero, so for a negative result the subtraction lands on the second after the moment. ToUnixTimeSeconds() returns the second that holds it. Half a second before the epoch, at 23:59:59.5 UTC on December 31, 1969, this code shows the gap:

C# before 1970
long ticks = DateTime.UnixEpoch.Ticks - 5_000_000; // half a second before 1970
Console.WriteLine((ticks - DateTime.UnixEpoch.Ticks) / TimeSpan.TicksPerSecond); // 0
Console.WriteLine(new DateTimeOffset(ticks, TimeSpan.Zero).ToUnixTimeSeconds()); // -1

When ticks leave .NET, in a database column or a JSON field, other languages can convert them too. Python's integers are exact, and its // rounds down, so the plain formula works for any date:

Python
ticks = 639161082000000000
seconds = (ticks - 621355968000000000) // 10_000_000  # 1780511400

JavaScript needs a BigInt, since a tick count is far past Number.MAX_SAFE_INTEGER. Read it from a string, because a plain number literal rounds the last digits before BigInt ever sees them. BigInt division rounds toward zero like C#, so the same care applies before 1970.

JavaScript
const ticks = BigInt("639161082000000000")
const ms = Number((ticks - 621355968000000000n) / 10_000n)
console.log(new Date(ms).toISOString()) // 2026-06-03T18:30:00.000Z

Ticks and a Windows FILETIME count the same 100-nanosecond steps, but FILETIME starts in 1601, at tick 504911232000000000. The FILETIME page covers that format and the Active Directory values that use it. For the negative timestamps themselves, see negative Unix timestamps.

The Unix Timestamp Converter shows the tick count for any moment in its Other Formats card. Paste ticks into that field to get the Unix timestamp and the date. If the ticks hold milliseconds, the timestamp switches to milliseconds. Anything finer is dropped, since the converter works in whole milliseconds.

Verdict

Go through DateTimeOffset when you can. UtcTicks and ToUnixTimeSeconds() always work in UTC, and the latter rounds down before 1970. When you do the math by hand, make sure the ticks came from a UTC value, floor the division for negative results, and keep the number in a 64-bit integer or a BigInt so its last digits survive.

More Timestamp scenarios

Frequently asked questions

How many ticks are in a second?
Ten million. TimeSpan.TicksPerSecond is 10,000,000, and a millisecond has 10,000 ticks. One tick is 100 nanoseconds, a ten-millionth of a second.
What is the tick count of the Unix epoch?
It's 621355968000000000, the ticks between January 1 of the year 1 and January 1, 1970. In C#, DateTime.UnixEpoch.Ticks returns it, and DateTimeOffset.FromUnixTimeSeconds(0).UtcTicks gives the same number.
Why is my converted time off by a few hours?
The ticks probably came from a local DateTime, like DateTime.Now. Its count includes the machine's offset from UTC, so the Unix time is off by that offset. Take ticks from DateTime.UtcNow, call ToUniversalTime() first, or use DateTimeOffset.UtcTicks.
Are .NET ticks the same as a Windows FILETIME?
No. They use the same 100-nanosecond step but start on different days: the year 1 for ticks and 1601 for a FILETIME. Move between them with DateTime.FromFileTimeUtc() and ToFileTimeUtc(), which also check that the value fits.
What's the largest date ticks can hold?
December 31, 9999. Microsoft says DateTime.MaxValue is "equivalent to 23:59:59.9999999 UTC, December 31, 9999". A Unix timestamp past that has no tick count, and DateTimeOffset.FromUnixTimeSeconds() throws for any value above 253,402,300,799.