/// <summary> /// 将 DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="time">时间</param> /// <returns>long</returns> public static long ConvertDateTimeToInt(DateTime time) { System.DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); long TimeStamp = (time.Ticks - Time.Ticks) / 10000; //除10000调整为13位 return TimeStamp; } /// <summary> /// 将Unix时间戳格式 转换为DateTime时间格式 /// </summary> /// <param name="time">时间</param> /// <returns>long</returns> public static DateTime ConvertDateTimeToInt(long time) { System.DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); DateTime dateTime = Time.AddMilliseconds(time); return dateTime; }