Parsing unix time in C#

后端 未结 9 717
悲&欢浪女
悲&欢浪女 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:36

    I realize this is a fairly old question but I figured I'd post my solution which used Nodatime's Instant class which has a method specifically for this.

    Instant.FromSecondsSinceUnixEpoch(longSecondsSinceEpoch).ToDateTimeUtc();
    

    I totally get that maybe pulling in Nodatime might be heavy for some folks. For my projects where dependency bloat isn't a major concern I'd rather rely on maintained library solutions rather than having to maintain my own.

提交回复
热议问题