将Long类型转换为DateTime类型
/// <summary> /// 将Long类型转换为DateTime类型 /// </summary> /// <param name="d">long</param> /// <returns></returns> public static DateTime ConvertLongDateTime(long ticks) { DateTime dtBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime convertTime = dtBase.Add(new TimeSpan(ticks * TimeSpan.TicksPerMillisecond)).ToLocalTime(); return convertTime; }
将DateTime类型转换为long类型
/// <summary> /// 将DateTime类型转换为long类型 /// </summary> /// <param name="dt">时间</param> /// <returns></returns> public static long ConvertDataTimeLong(DateTime dt) { DateTime dtBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan toNow = DateTime.Now.Subtract(dtBase); long timeStamp = toNow.Ticks; return timeStamp; }
时间: 2024-10-25 00:57:32