--返回明天第N点的时间戳
function getNextDayTime(N)
local t = os.date("*t", MasterInfo.getServerTime());
local nextDayTime = {year = t.year, month = t.month , day = t.day + 1, hour=N,min=0,sec=0}
return os.time(nextDayTime)
end
--返回当天第N点的时间戳
function getTodayTime(N)
local t = os.date("*t", MasterInfo.getServerTime());
local todayTime = {year = t.year, month = t.month , day = t.day , hour=N or 0,min=0,sec=0}
return os.time(todayTime)
end
--返回某天第N点的时间戳
function getSomeDayTime(t, N)
local t = os.date("*t", t);
local someDayTime = {year = t.year, month = t.month , day = t.day , hour=N or 0,min=0,sec=0}
return os.time(someDayTime)
end
-- 判断一个时间点是否在今日以内
function isToday(dt)
if not dt then return false end
local s1 = os.date("%Y%m%d",MasterInfo.getServerTime())
local s2 = os.date("%Y%m%d",dt)
return s1 == s2
end
-- 判断是否同一天
-- @param epoch1 unix时间戳(秒)
-- @param epoch2 unix时间戳(秒)
-- @return true表示同一天
-- false表示不是同一天
function isSameDate(epoch1, epoch2)
local date1 = os.date("%x", epoch1)
local date2 = os.date("%x", epoch2)
return date1 == date2
end
function getDateTime(t)
local tt = os.date("*t", t);
return tt.year,tt.month,tt.day,tt.hour,tt.min,tt.sec
end
function getTimeByString(str)
-- str 格式 YYYYMMDDhhmmss
local year = tonumber(string.sub(str,1,4))
local month = tonumber(string.sub(str,5,6))
local day = tonumber(string.sub(str,7,8))
local hour = tonumber(string.sub(str,9,10)) or 0
local min = tonumber(string.sub(str,11,12)) or 0
local sec = tonumber(string.sub(str,13,14)) or 0
local timeTable = {year = year, month = month ,
Lua时间相关函数
于 2022-02-24 11:20:38 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)