EpochTools

.NET DateTimeOffset

Get the current Unix timestamp in C#

.NET stores dates as ticks since 0001-01-01, so epoch conversion always involves an offset from `DateTimeOffset.FromUnixTimeSeconds()` and `ToUnixTimeSeconds()`.

`DateTimeOffset.Now.ToUnixTimeSeconds()` is the idiomatic way to read the current epoch in C#.

Current Unix timestamp (seconds)

long now = DateTimeOffset.Now.ToUnixTimeSeconds();
Console.WriteLine(now); // 1,754,136,000

Convert epoch seconds → ISO 8601 (UTC)

var dt = DateTimeOffset.FromUnixTimeSeconds(1754136000);
Console.WriteLine(dt.UtcDateTime.ToString("o")); // 2025-08-02T12:00:00.0000000Z

Real-world use cases for C#

  • Storing audit events as long epoch seconds in an EF Core or Dapper model.
  • Setting JWT exp claims using DateTimeOffset.Now.ToUnixTimeSeconds().
  • Converting Unix timestamps returned by Redis or Stripe into DateTimeOffset for display.
Unix timestamp (seconds) ISO 8601 (UTC)
0 1970-01-01T00:00:00.000Z
946,684,800 2000-01-01T00:00:00.000Z
1,754,136,000 2025-08-02T12:00:00.000Z
2,147,483,647 2038-01-19T03:14:07.000Z
2,524,608,000 2050-01-01T00:00:00.000Z

These are the same fixed timestamps used in the C# examples above — every conversion returns one of these values.

Frequently asked questions

How do I get the current Unix timestamp in C#?

DateTimeOffset.Now.ToUnixTimeSeconds() returns the current epoch in seconds, and .ToUnixTimeMilliseconds() returns milliseconds. DateTimeOffset is the .NET type built for exactly this conversion.

How do I convert an epoch timestamp to a date in C#?

DateTimeOffset.FromUnixTimeSeconds(1754136000) converts epoch seconds to a DateTimeOffset. Call .UtcDateTime for UTC or .ToLocalTime() for the local timezone, then format with ToString("o") for ISO 8601.

Why does .NET not store epoch seconds directly?

.NET dates are stored as ticks since 0001-01-01. The DateTimeOffset.FromUnixTimeSeconds() / ToUnixTimeSeconds() pair converts to and from the Unix epoch, so you get the best of both worlds without managing the math yourself.

Epoch to human date in C#

Try it live — convert any timestamp in C#-friendly format.

Seconds or milliseconds — the unit is auto-detected. Example: 1735689600

Waiting for input…

UTC ISO 8601

–

Local — auto

–

RFC 2822 / GMT

–

Seconds value

–

Relative time

–

Other programming languages

Copy-paste epoch conversion snippets in your favorite stack

View all code snippets →

More timestamp guides

Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.