时间按指定格式转换

简介: unity玩转时间格式转换
推荐阅读:

一。把秒数转换成 00:00:00 大于一天显示 1天2时

local function second2DHMS(second)
    if second <= 0 then
        return 0,0,0,0
    end
    local d = math.floor(second / 86400)
    second = second - d * 86400

    local h = math.floor(second / 3600)
    second = second - h * 3600

    local m = math.floor(second / 60)
    second = second - m * 60

    local s = second

    return d, h, m, s
end
local function gettimestrDay(second)
    local _d, _h, _m, _s =second2DHMS(second)

    local timedata = ""

    if _d > 0 then
        timedata = _d.."天".._h.."小时"
    else
        if _h < 10 then
            _h = "0".._h
        end
        if _m < 10 then
            _m = "0".._m
             
        end
        if _s < 10 then
            _s = "0".._s
        end
        timedata = _h..":".._m..":".._s
    end
    return timedata
end

二。把秒数转换成 00:00:00

-- 把秒数转换成 00:00:00 
local function gettimestr(second)
    local hour = math.floor(second / 3600)
    local min = math.floor(second % 3600 / 60)
    local sec = second % 60
     
    return string.format("%02d:%02d:%02d", hour, min, sec)
end

三。时间戳转换为 2022.1.12

--时间戳转换为:2022.1.12
function GetTimeStamp(t)
     return  os.date( "%Y.%m.%d" ,t)
end

四。把秒数转换成 分钟:秒数 00:00

local function gettimestr2(second)
    local min = math.floor(second/60)
    local sec = second % 60
    return string.format("%02d:%02d", min, sec)
end

五。把秒数转换成 小时:分钟 00:00

local function gettimestr3(second)
    local hour = math.floor(second / 3600)
    local min = math.floor(second % 3600 / 60)
    return string.format("%02d:%02d", hour, min)
end

六。把秒数转成 x小时x分钟

local function gettimestr4(second)
    local hour = math.floor(second / 3600)
    local min = math.floor(second % 3600 / 60)
    if hour > 0 then
        return string.format("%d小时%d分钟", hour, min)
    end
    return string.format("%d分钟", min)
end

七。把秒数转成 x小时x分钟x秒

local function gettimestr5(second)
    local hour = math.floor(second / 3600)
    local min = math.floor(second % 3600 / 60)
    local sec = second % 60
    if hour > 0 then
        return string.format("%d小时%d分钟%d秒", hour, min, sec)
    end
    return string.format("%d分钟%d秒", min, sec)
end

八。把秒数转成 x天x小时x分钟x秒

local function gettimestr6(second)
    local day = math.floor(second / 86400)
    local hour = math.floor(second % 86400 / 3600)
    local min = math.floor(second % 3600 / 60)
    local sec = second % 60
    
    return string.format("%d天%d小时%d分钟%d秒", day, hour, min, sec)
end

九。把秒数转成 x天x小时

local function gettimestr7(second)
    local day = math.floor(second / 86400)
    local hour = math.floor(second % 86400 / 3600)
    
    return string.format("%d天%d小时", day, hour)
end

十。把秒数转成 x天

local function gettimestr8(second)
    local day = math.floor(second / 86400)
    local hour = math.floor(second % 86400 / 3600)
    
    return string.format("%d天", day)
end
相关文章
|
8月前
h264编码一帧所用时间
h264编码一帧所用时间
112 0
h264编码一帧所用时间
|
8月前
时间戳转换时间
时间戳转换时间
|
3月前
Excel中时间戳与标准日期格式的互相转换
Excel中时间戳与标准日期格式的互相转换
60 0
Excel中时间戳与标准日期格式的互相转换
|
3月前
Qt 时间戳和时间相关的转换操作
Qt 时间戳和时间相关的转换操作
72 0
|
4月前
|
前端开发
dayjs格式转换成日期
dayjs格式转换成日期
71 0
dayjs格式转换成日期
|
编解码 Linux vr&ar
如何使用ffmpeg将.m4a 格式转换为 pcma格式
ffmpeg是一款开源的万能媒体格式转换工具。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的
|
定位技术 图形学
葛兰岱尔模型格式转换器
葛兰岱尔数字孪生模型格式转换器能够将几乎所有工程建筑行业的2D/3D/BIM/GIS模型数据转换输出为Unreal(UE)、Unity3D、Cesium、ThreeJS等开源平台支持的模型格式,包括: gltf、glb、标准3Dtiles、fbx、obj
160 0
葛兰岱尔模型格式转换器
|
Python
RLE格式转换
RLE格式转换
164 0
|
程序员 Windows
视频格式转换
视频格式转换
293 0
封装时间戳转具体时间工具
封装时间戳转具体时间工具
122 0
封装时间戳转具体时间工具