C# Unix时间戳和DateTime类型转换

/// 
        /// 将Unix时间戳转换为DateTime类型时间
        /// 
        /// double 型数字
        /// DateTime
        public static System.DateTime ConvertIntDateTime(double d)
        {
            System.DateTime time = System.DateTime.MinValue;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            time = startTime.AddMilliseconds(d);
            return time;
        }

        /// 
        /// 将c# DateTime时间格式转换为Unix时间戳格式
        /// 
        /// 时间
        /// long
        public static long ConvertDateTimeInt(System.DateTime time)
        {
            //double intResult = 0;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970,1,1,0,0,0,0));
            //intResult = (time- startTime).TotalMilliseconds;
            long t = (time.Ticks - startTime.Ticks)/10000;            //除10000调整为13位
            return t;
        }

你可能感兴趣的:(C#)