/// <summary>
/// 将DateTime类型转换为long类型
/// </summary>
/// <param name="dt">时间</param>
/// <returns></returns>
public static long ConvertDataTimeLong(DateTime dt)
{
//dateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000
DateTime dtBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
TimeSpan toNow = dt.ToUniversalTime().Subtract(dtBase);
long timeStamp = toNow.Ticks / 10000;
return timeStamp;
}
/// <summary>
/// 将long类型转换为DateTime类型
/// </summary>
/// <param name="timeStamp">时间戳</param>
/// <returns></returns>
public static DateTime ConvertLongtoDataTime(long timeStamp)
{
DateTime dtBase = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(timeStamp);
return dtBase;
}`