using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InvoicingTool { /// /// 时间戳转换 /// class TimeHelper { /// /// 将DateTime类型转换为long类型 /// /// 时间 /// public static long ConvertDataTimeLong(DateTime dt) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); TimeSpan toNow = dt.Subtract(dtStart); long timeStamp = toNow.Ticks; timeStamp = long.Parse(timeStamp.ToString().Substring(0, timeStamp.ToString().Length - 7)); return timeStamp; } /// /// 将Long类型转换为DateTime类型 /// /// long /// s public static DateTime ConvertLongDateTime(long d) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(d + "0000000"); TimeSpan toNow = new TimeSpan(lTime); DateTime dtResult = dtStart.Add(toNow); return dtResult; } } }