/// <summary> /// 本地时间转时间戳(毫秒) /// </summary> /// <returns></returns> public static long ConvertToLong(DateTime time) { DateTime sDate = XfwCommon.ToLocalTime(new DateTime(1970, 1, 1)); TimeSpan ts = time.Subtract(sDate); long ticks = ts.Ticks; ticks = long.Parse(ticks.ToString().Substring(0, ticks.ToString().Length - 4)); return(ticks); }
/// <summary> /// 时间戳转为本地时间(秒) /// </summary> /// <param name="sec">是已秒做单位的时间戳</param> /// <returns></returns> public static DateTime ConvertToDateTimeSec(string sec) { DateTime sDate = XfwCommon.ToLocalTime(new DateTime(1970, 1, 1)); long ticks = long.Parse(sec + "0000000"); TimeSpan toNow = new TimeSpan(ticks); DateTime nDate = sDate.Add(toNow); return(nDate); }
/// <summary> /// 时间戳转为本地时间(毫秒) /// </summary> /// <returns></returns> public static DateTime ConvertToDateTime(long ticks) { DateTime sDate = XfwCommon.ToLocalTime(new DateTime(1970, 1, 1)); ticks = long.Parse(ticks + "0000"); TimeSpan ts = new TimeSpan(ticks); DateTime nDate = sDate.Add(ts); return(nDate); }
/// <summary> /// long 型转日期 Unix /// </summary> /// <returns></returns> public static DateTime ConvertToDateTimeUnix(string s) { long d = long.Parse(s); return(XfwCommon.ConvertToDateTimeUnix(d)); }
/// <summary> /// 本地时间转时间戳(秒) /// </summary> public static long ConvertToLongSec(DateTime date) { System.DateTime sDate = XfwCommon.ToLocalTime(new DateTime(1970, 1, 1)); return((long)(date - sDate).TotalSeconds); }
/// <summary> /// 本地时间转时间戳(秒) /// </summary> public static long ConvertToLongSec(string date) { System.DateTime eDate = DateTime.Parse(date); System.DateTime sDate = XfwCommon.ToLocalTime(new DateTime(1970, 1, 1)); return((long)(eDate - sDate).TotalSeconds); }