【.NET】 C# 时间戳和DataTime 互相转换
2021-06-06 14:02
标签:current style data sys strong zone cond pre col 1.C# DateTime转换为Unix时间戳 2.Unix时间戳转换为C# DateTime 【.NET】 C# 时间戳和DataTime 互相转换 标签:current style data sys strong zone cond pre col 原文地址:https://www.cnblogs.com/wangsure/p/10777258.html1 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
2 long timeStamp = (long)(DateTime.Now - startTime).TotalSeconds; // 相差秒数
3 System.Console.WriteLine(timeStamp);
1 long unixTimeStamp = 1478162177;
2 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
3 DateTime dt = startTime.AddSeconds(unixTimeStamp);
4 System.Console.WriteLine(dt.ToString("yyyy/MM/dd HH:mm:ss:ffff"));
文章标题:【.NET】 C# 时间戳和DataTime 互相转换
文章链接:http://soscw.com/index.php/essay/91299.html