using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HuizhongLibrary { public static class DateUtils { public static long ToTimestamp(this DateTime dateTime) { DateTime historyDate = new DateTime(1970, 1, 1); long timestamp = (dateTime.Ticks - historyDate.Ticks) / 10000000 - 8 * 60 * 60; return timestamp; } public static DateTime ToDateTime(this long timestamp) { DateTime historyDate = new DateTime(1970, 1, 1); long timeTicks = (timestamp + 8 * 60 * 60) * 10000000 + historyDate.Ticks; return DateTime.FromBinary(timeTicks); } /// /// 获取北京时间 /// /// public static DateTime GetBJNow() { return DateTime.Now.ToUniversalTime().AddHours(8); } } }