How can I convert a Unix timestamp to DateTime and vice versa?

前端 未结 19 2415
抹茶落季
抹茶落季 2020-11-21 06:37

There is this example code, but then it starts talking about millisecond / nanosecond problems.

The same question is on MSDN, Seconds since the Unix epoch in C#<

19条回答
  •  攒了一身酷
    2020-11-21 07:01

    From .net 4.6, you can do this:

    var dateTime = DateTimeOffset.FromUnixTimeSeconds(unixDateTime).DateTime;
    

提交回复
热议问题