Does the .NET framework support getting the current time in seconds based on UNIX timestamp?

后端 未结 2 1451
半阙折子戏
半阙折子戏 2021-01-17 21:14

I am wondering if .NET contains a method to convert the current time in seconds or milliseconds to a UNIX timestamp (offset from 1970/1/1)?

2条回答
  •  心在旅途
    2021-01-17 21:51

    you can get the ticks from 1970 (ie the UNIX timestamp) like this:

    TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970,1,1,0,0,0);
    double unixVersion = timeSpan.TotalSeconds;
    

提交回复
热议问题