用户登录
用户注册

分享至

Lua时间转化的几个小例子

  • 作者: 纸鸢寻芊风不殇
  • 来源: 51数据库
  • 2021-07-08

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


--把时间 秒,转化为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))

软件
前端设计
程序设计
Java相关