public class DateTimeUtil { private static DateTime utcStartTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); /// <summary> /// 转换为DateTime /// </summary> /// <param name="timeStamp">10位时间戳(单位:毫秒)</param> /// <returns>DateTime</returns> public static DateTime TimeStampToDateTime(long timeStamp) { return utcStartTime.AddMilliseconds(timeStamp).ToLocalTime(); } /// <summary> /// DateTime转换为时间戳 /// </summary> /// <param name="dateTime"> DateTime</param> /// <returns>10位时间戳(单位:毫秒)</returns> public static long DateTimeToTimeStamp(DateTime dateTime) { return (long)(dateTime.ToUniversalTime() - utcStartTime).TotalMilliseconds; } }
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/275198.html