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)
  • 相关阅读:
    MIME类型大全
    Asp.net中解决“请求超时”的问题
    C#日期函数所有样式大全
    [转]Oracle数据关联查询
    convert时间格式转换参数表 [收藏]
    vs2008安装失败。解决办法。部分。
    asp.net获取web.config配置信息
    jQuery UI Dialog控件中的表单无法正常提交的解决方法
    控制Button在数据验证成功才执行后台方法
    关于使用DataTable.Compute()方法时报“聚合参数中的语法错误: 需要具有可能的“Child”限定符的单个列参数。”
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/5224022.html
Copyright © 2011-2022 走看看