Parsing unix time in C#

Viewed 17353

Is there a way to quickly / easily parse Unix time in C# ? I'm brand new at the language, so if this is a painfully obvious question, I apologize. IE I have a string in the format [seconds since Epoch].[milliseconds]. Is there an equivalent to Java's SimpleDateFormat in C# ?

9 Answers

Since .NET 4.6, you can use DateTimeOffset.FromUnixTimeSeconds() and DateTimeOffset.FromUnixTimeMilliseconds():

long unixTime = 1600000000;
DateTimeOffset dto = DateTimeOffset.FromUnixTimeSeconds(unixTime);
DateTime dt = dto.DateTime;
Related