时间函数:
local now = os.time()
local curTime = os.date("*t", now)
local curWeek = os.date("%w",now) --星期天是0
print(curTime.year, curTime.month, curTime.day, curTime.hour, curTime.min, curTime.sec, curWeek)
--注意区分大小写:
local timeStr = os.date("%Y-%m-%d %H:%M:%S", now) --2021-09-19 15:32:41
local timeStr = os.date("%Y/%m/%d is %A", now) --2021/09/19 is Sunday
--%w:星期天为0
local timeStr = os.date("%Y/%m/%d is %w", now) --2022/03/01 is 2
@比较两个时间戳,返回相差多少天
function timediff(begin_time,end_time)
if begin_time < end_time then
starttime = begin_time;
endtime = end_time;
else
starttime = end_time;
endtime = begin_time;
end
--计算天数
timediff = endtime-starttime;
days = math.floor(timediff/86400);
--计算小时数
remain = timediff%86400;
hours = math.floor(remain/3600);
--计算分钟数
remain = remain%3600;
mins = math.floor(remain/60);
--计算秒数
se
Lua中时间函数的用法整理
于 2021-09-27 15:44:39 首次发布