//检查时间
DateTime start = DateTime.Now;
DateTime end = DateTime.Now;
TimeSpan ts = (end - start);
/// <summary>
/// 将Unix时间戳转换为dateTime格式
/// </summary>
/// <param name="unix"></param>
/// <returns></returns>
public static DateTime ConvertUnixToDateTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
/// <summary>
/// 将dateTime格式转换为Unix时间戳
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public long ConvertDateTimeToUnix(DateTime time)
{
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
return (long)(time - startTime).TotalMilliseconds;
}
时间格式: long time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
13位时间戳转换成yyyy-dd-mm
long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
String tomorrow = Convert.ToString(GetDateTimeMilliseconds(now)).Substring(0,9);
tomorrow=tomorrow.Replace("/", "-");
public static DateTime GetDateTimeMilliseconds(long timestamp)
{
long begtime = timestamp * 10000;
DateTime dt_1970 = new DateTime(1970, 1, 1, 8, 0, 0);
long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度
long time_tricks = tricks_1970 + begtime;//日志日期刻度
DateTime dt = new DateTime(time_tricks);//转化为DateTime
return dt;
}
//23时59分59秒 86400000 -1