zoukankan      html  css  js  c++  java
  • 日期类型转换时间戳及时间戳转时间类型

     
    //日期转时间戳  
          public static long DateTimeToUnixTimestamp(DateTime dateTime)
            {
                return (dateTime.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
            }
    
    //时间戳转日期
    public static DateTime ToDateTime(this string timestamp)
    {
            if(string.IsNullOrEmpty(timestamp))
           {
            throw new ArgumentNullException(timestamp);
           }
            DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
        long lTime = long.Parse(timestamp + "0000000");
        TimeSpan toNow = new TimeSpan(lTime);
        return dateTimeStart.Add(toNow);
    }
    
     
    /// <summary>
    /// unix时间戳转换成日期
    /// </summary>
    /// <param name="unixTimeStamp">时间戳(秒)</param>
    /// <returns></returns>
    public static DateTime UnixTimestampToDateTime(this DateTime target, long timestamp)
    {
        var start = new DateTime(1970, 1, 1, 0, 0, 0, target.Kind);
        return start.AddSeconds(timestamp);
    }
    
            /// <summary>
            /// unix时间戳转换成日期
            /// </summary>
            /// <param name="unixTimeStamp">时间戳(秒)</param>
            /// <returns></returns>
            public static DateTime UnixTimestampToDateTime(long timestamp)
            {
                var start = new DateTime(1970, 1, 1, 8, 0, 0, DateTimeKind.Unspecified);
                return start.AddMilliseconds(timestamp);
            }  
     版本号相关操作
     --/// <summary>
            --/// 已运行的最大行版本号
            --/// </summary>
            --public static byte[] RunMaxVersionNum = { 0x0 };
              --var nowMaxVersionNum = channelCommDal.GetMaxVersionNum(dbConnection);
              --        public byte[] GetMaxVersionNum(IDbConnection dbConnection)
        --    {
        --        return DbHelper.Default.QueryScalar<byte[]>(dbConnection,
        --            "SELECT MAX(VersionNum) FROM dbo.Fct_ChannelCommodity");
        --    }
    
               --var runVersionNum = "0x" + BitConverter.ToString(RunMaxVersionNum).Replace("-", "");
    
            --public static bool ByteEquals(byte[] b1, byte[] b2)
            --{
            --    if (b1 == null && b2 == null)
            --    {
            --        return true;
            --    }
            --    if (b1 == null || b2 == null)
            --        return false;
            --    if (b1.Length != b2.Length)
            --        return false;
            --    return !b1.Where((t, i) => t != b2[i]).Any();
            --}
            
            --if (ByteEquals(nowMaxVersionNum, RunMaxVersionNum))
            
            -- Version = Math.Abs(Guid.NewGuid().GetHashCode()).ToString(),   --nvarchar(64)
  • 相关阅读:
    Struts2的struts.properties文件在哪儿啊?
    StrutsPrepareAndExecuteFilter的作用
    【转】Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    怎么找到MyEclipse->add struts capabilities
    图像金字塔
    浅析人脸检测之Haar分类器方法
    SIFT算法学习
    OpenCV3.1使用SIFT
    OpenCV头文件包含问题
    OpenCV例程实现人脸检测
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/5224022.html
Copyright © 2011-2022 走看看