时间戳转日期
os.date("%Y-%m-%d %H:%M:%S",timestamp)
日期转时间戳
os.time({year = 2020, month = 12, day = 8, hour = 0, minute = 0, second = 0})
转成年月日Table
function FormatUnixTime2Date(unixTime)
if unixTime and unixTime >= 0 then
local tb = {}
tb.year = tonumber(os.date("%Y", unixTime))
tb.month = tonumber(os.date("%m", unixTime))
tb.day = tonumber(os.date("%d", unixTime))
tb.hour = tonumber(os.date("%H", unixTime))
tb.minute = tonumber(os.date("%M", unixTime))
tb.second = tonumber(os.date("%S", unixTime))
return tb
end
end
判断两个时间戳是否同一天
function IsOneDay(time1, time2)
time1 = tonumber(time1)
time2 = tonumber(time2)
if time1 > 0 and time2 > 0 then
time1 = FormatUnixTime2Date(time1)
time2 = FormatUnixTime2Date(time2)
if time1.day == time2.day and time1.month == time2.month and time1.year == time2.year then
return true
end
return false
end
end
参考
https://www.cnblogs.com/zhaoqingqing/p/9487479.html