Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// long 型转日期 Unix
        /// </summary>
        /// <returns></returns>
        public static DateTime ConvertToDateTimeUnix(string s)
        {
            long d = long.Parse(s);

            return(XfwCommon.ConvertToDateTimeUnix(d));
        }
Exemplo n.º 5
0
 /// <summary>
 /// 本地时间转时间戳(秒)
 /// </summary>
 public static long ConvertToLongSec(DateTime date)
 {
     System.DateTime sDate = XfwCommon.ToLocalTime(new DateTime(1970, 1, 1));
     return((long)(date - sDate).TotalSeconds);
 }
Exemplo n.º 6
0
 /// <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);
 }