Unix时间戳转换

        /// <summary>
        /// 将Unix时间戳转换为DateTime类型时间
        /// </summary>
        /// <param name="d">double 型数字</param>
        /// <returns>DateTime</returns>
        public static System.DateTime ConvertIntDateTime(double d)
        {
            //SQL Server 转换:select DATEADD(s, 1516866377, '1970-01-01 00:00:00')
            //MySql 转换: FROM_UNIXTIME(1516866377)as servertime
//MySql 毫秒格式时间戳转换 要除以1000就变成秒格式 FROM_UNIXTIME(floor((1528681728997/1000)))as curtime
System.DateTime time = System.DateTime.MinValue; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); time = startTime.AddSeconds(d); return time; } /// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// 直接用(DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 可获得当前时间的Unix时间戳 /// </summary> /// <param name="time">时间</param> /// <returns>double</returns> public static double ConvertDateTimeInt(System.DateTime time) { //SQL Server 转换:SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) double intResult = 0; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); intResult = (time - startTime).TotalSeconds; return intResult; }

Unix时间戳在线转换工具

http://tools.sharejs.com/unixtime.html

tool.chinaz.com/Tools/unixtime.aspx

原文地址:https://www.cnblogs.com/zyx321/p/8351600.html