using System; namespace TBL.CSharp.Base { public static partial class Extension { /// /// 从 Unix 时间戳转换为 结构 /// public static DateTime FromUnixTime(this long unixTime) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); return epoch.AddSeconds(unixTime); } /// /// 从 结构转换为 Unix 时间戳 /// public static long ToUnixTime(this DateTime date) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); return Convert.ToInt64((date - epoch).TotalSeconds); } } }