• 日期类型转换时间戳及时间戳转时间类型


     
    //日期转时间戳  
          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)
  • 相关阅读:
    MongoDB 组合多个条件查询($and、$in、$gte、$lte)
    KafkaConsumer 长时间地在poll(long )方法中阻塞
    Spring MVC整合Mybatis 入门
    JAVA正确地自定义比较对象---如何重写equals方法和hashCode方法
    MyBatis简单使用和入门理解
    使用二分查找判断某个数在某个区间中--如何判断某个IP地址所属的地区
    FastJson使用示例
    linux(ubuntu) 开发环境配置
    android自定义风格的toast
    iPhone跳转的动画效果类型及实现方法 CATransition
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/5224022.html
Copyright © 2020-2023  润新知