Code snippets / C#
How to 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 Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z
Need more languages? Browse all the Unix timestamp code snippets. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.
Epoch → Human Date
Try it live — convert any timestamp in C#-friendly format.
Seconds or milliseconds — the unit is auto-detected. Example: 1735689600
UTC ISO 8601
–
Local — auto
–
RFC 2822 / GMT
–
Seconds value
–
Relative time
–