lua10进制转bit
local function number2bit(n)
local t = {}
for i = 7, 0, -1 do
t[#t + 1] = math.floor(n / 2 ^ i)
n = n % 2 ^ i
end
return t
end
local v = number2bit(255)
for _, value in ipairs(v) do
print(value)
end
print(tonumber(table.concat(v), 2))
lua断两个时间戳差天数
--判断两个时间戳差天数
local function getDateNum(timeNow, timeNext)
local ret = 0
if timeNow and timeNext then
local now = os.date('*t', timeNow)
local next = os.date('*t', timeNext)
if now and next then
local num1 = os.time({year = now.year, month = now.month, day = now.day})
local num2 = os.time({year = next.year, month = next.month, day = next.day})
if num1 and num2 then
ret = math.abs(num1 - num2) / (3600 * 24)
ret = math.modf(ret)
end
end
end
return ret
end
lua判断两个时间戳是否为同一天
local function isToday(timestamp)
local today = os.date('*t',1647187200)
local secondOfToday =
os.time({day = today.day, month = today.month, year = today.year, hour = 0, minute = 0, second = 0})
if timestamp >= secondOfToday and timestamp < secondOfToday + 24 * 60 * 60 then
return true
else
return false
end
end