Epoch Time ConversionΒΆ

JWT tokens use so called Epoch or Unix time to represent date/times.

IdentityModel contains extensions methods for DateTime and DateTimeOffset or convert to/from Unix time:

var dt = DateTime.UtcNow;
var unix = dt.ToEpochTime();


Starting with .NET Framework 4.6 and .NET Core 1.0 this functionality is built-in via DateTimeOffset.FromUnixTimeSeconds and DateTimeOffset.ToUnixTimeSeconds.