zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    思考--连续的还是跳跃的?(二)
    方法学导论--by 有只茄子
    时空、维度,以及其他(一)
    处理问题的方法--抽象和特例化
    tomcat server 152主机.xml
    java怎么重写覆盖Spring Bean的几种方式
    maven上传jar到私服
    sql_mode=only_full_group_by
    spring何时创建bean
    mysql 快速备份数据库
  • 原文地址:https://www.cnblogs.com/zyx321/p/8351600.html
Copyright © 2011-2022 走看看