C#时间格式转换为时间戳互转
/// <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; }
从此山高路远,纵马扬鞭。愿往后旅途,三冬暖,春不寒,天黑有灯,下雨有伞。此生尽兴,不负勇往。