.NET Ticks to Unix Timestamp Converter
Convert a .NET DateTime.Ticks value to a Unix timestamp in seconds and milliseconds, ISO 8601, and a readable date. .NET ticks count 100-nanosecond intervals since January 1, 0001.
100-ns intervals since 0001-01-01
What are .NET ticks?
In .NET, DateTime.Ticks and TimeSpan.Ticks measure time in 100-nanosecond units. A DateTime tick count is the number of 100-nanosecond intervals since 00:00:00 on January 1, 0001 in the proleptic Gregorian calendar.
- Epoch: 0001-01-01 00:00:00
- Resolution: 100-nanosecond ticks (10,000,000 per second)
- A present-day value is around 6.4 × 10^17
- C#: DateTime.UtcNow.Ticks, DateTimeOffset.UtcNow.Ticks
How to convert .NET ticks to a Unix timestamp
There are 62,135,596,800 seconds between 0001-01-01 and 1970-01-01. Divide ticks by 10,000,000 for seconds since year 1, then subtract that offset.
- Unix seconds = Ticks / 10000000 − 62135596800
- Unix milliseconds = Ticks / 10000 − 62135596800000
- Example: 638355968000000000 → 1700000000 → 2023-11-14 22:13:20 UTC
- In C#: new DateTimeOffset(dt).ToUnixTimeSeconds() does this for you
C# code and edge cases
Modern .NET offers DateTimeOffset.ToUnixTimeSeconds() and ToUnixTimeMilliseconds(), and DateTimeOffset.FromUnixTimeSeconds() for the reverse. Use ticks directly only when interoperating with serialized data. Note that DateTime.Ticks ignores the DateTimeKind, so always normalize to UTC first.
- C#: var unixSeconds = new DateTimeOffset(dt.ToUniversalTime()).ToUnixTimeSeconds();
- C#: var dt = DateTimeOffset.FromUnixTimeMilliseconds(ms).UtcDateTime;
- Ticks of 0 = 0001-01-01; DateTime.MaxValue.Ticks = 3155378975999999999
- Values exceed JavaScript safe integers, so this converter uses BigInt
Related timestamp format converters
Library and serialization notes
Ticks turn up in older .NET serialization formats and JSON conventions. Watch for:
- Legacy Microsoft JSON dates: "/Date(1700000000000+0000)/" wrap milliseconds (not ticks)
- DateTimeOffset.UnixEpoch is the standard zero point in modern .NET
- DateTime.MaxValue.Ticks = 3155378975999999999; values that high almost certainly indicate a "never" sentinel
- TimeSpan.Ticks is the same unit but measured as a duration; do not subtract a DateTime tick from a TimeSpan tick blindly
- Newtonsoft.Json and System.Text.Json both default to ISO 8601 — prefer that over raw ticks where you have the choice
FAQ
- How many ticks are in a second?
- Exactly 10,000,000 ticks — each tick is 100 nanoseconds.
- What is the difference between .NET ticks and Windows FILETIME?
- Both use 100-nanosecond units, but .NET ticks count from 0001-01-01 while FILETIME counts from 1601-01-01. They differ by a fixed offset of 504,911,232,000,000,000 ticks.
- How do I get Unix time from a C# DateTime?
- Use new DateTimeOffset(dateTime.ToUniversalTime()).ToUnixTimeSeconds() or .ToUnixTimeMilliseconds().