For Developers

Unix Timestamp in C#

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in C# — plus the specific mistake that trips up C# code more than any other.

DateTimeOffset.UtcNow.ToUnixTimeSeconds()
DateTimeOffset.FromUnixTimeSeconds(1750000000)
DateTimeOffset.Parse("2025-06-15T12:00:00Z").ToUnixTimeSeconds()

The C#-specific pitfall

Use DateTimeOffset, not the older DateTime, for anything involving Unix timestamps — DateTime has a Kind property (Local/Utc/Unspecified) that's a frequent source of the exact same naive-vs-aware confusion Python has, and DateTimeOffset sidesteps it by always carrying an explicit offset.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading