/// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="time">时间</param> /// <returns>long</returns> public static long ConvertDateTimeToLong(DateTime time) { DateTime startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, 0), TimeZoneInfo.Local); long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 return t; } /// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></param> /// <returns></returns> public static DateTime ConvertLongToDateTime(long timeStamp) { DateTime dtStart = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, 0), TimeZoneInfo.Local); long lTime = timeStamp * 10000; TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow); }
原文地址:https://www.cnblogs.com/chongyao/p/12213084.html
时间: 2024-11-08 00:14:12