Parsing unix time in C#

后端 未结 9 716
悲&欢浪女
悲&欢浪女 2020-11-30 10:13

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 th

9条回答
  •  借酒劲吻你
    2020-11-30 10:39

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

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

提交回复
热议问题