您的位置:首页 > 编程语言 > Lua

Lua时间转化的几个小例子

2017-07-19 11:53 204 查看
1、把时间 秒,转化为xx天xx时xx分xx秒 的形式

function convertTimeForm(second)
local timeDay = math.floor(second/86400)
local timeHour = math.fmod(math.floor(second/3600), 24)
local timeMinute = math.fmod(math.floor(second/60), 60)
local timeSecond = math.fmod(second, 60)

return timeDay, timeHour, timeMinute, timeSecond
end

2、把时间 秒,转化为xx时xx分xx秒 的形式

local function formatTime(time)
local hour = math.floor(time/3600);
local minute = math.fmod(math.floor(time/60), 60)
local second = math.fmod(time, 60)
local rtTime = string.format("%s:%s:%s", hour, minute, second)
return rtTime
end

3.把1990.1.1至今的秒数,转化为年月日,时分。注:endTime 单位毫秒

os.date("%Y-%m-%d  %H:%M",math.floor(endTime/1000))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: