time_t到NET DateTimeの変換

800 ワード

time関数が返すtime_tはutc時間であり、1970年1月1日のtotal secondsに対してDateTimeに変換するには同じ方法で変換すればよい.
C/C++
auto t = time(0);

C#.NET
var t = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
var dt = new DateTime(1970, 1, 1).AddSeconds(1384771739).ToLocalTime();