//日期转时间戳 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)