C# 获取当前时间戳和将时间戳转为时间Datetime类型的方法
/// <summary> /// 获取时间戳(精确到毫秒) /// </summary> /// <param name="time">时间</param> public static long ConvertDateTiemp(DateTime time) { return ((time.ToUniversalTime().Ticks - 621355968000000000) / 10000000) * 1000; } /// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name="timeStamp"></param> /// <returns></returns> public static DateTime GetTime(string timeStamp) { if (timeStamp.Length > 10) { timeStamp = timeStamp.Substring(0, 10); } DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(lTime); return dateTimeStart.Add(toNow); }