时间及时间戳相互转换

        #region 时间,时间戳转换
        /// 
        /// 时间转换为事件戳
        /// 
        /// 
        /// 
        public static uint GetTimeStamp(DateTime dateTime)
        {
            DateTime DateStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));          
            return Convert.ToUInt32((dateTime - DateStart).TotalSeconds);
        }

        /// 时间戳转为C#格式时间  
        ///   
        ///   
        ///   
        public static DateTime GetTimeFromUint(string timeStamp)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = long.Parse(timeStamp + "0000000");
            TimeSpan toNow = new TimeSpan(lTime); 
            return dtStart.Add(toNow);
        }
        #endregion

你可能感兴趣的:(时间及时间戳相互转换)