• 时间按指定格式转换


    推荐阅读:

    一。把秒数转换成 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
    

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

    local function gettimestr1(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
    

    四。把秒数转换成 分钟:秒数 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
    
  • 相关阅读:
    sql in not in 案例用 exists not exists 代替
    根据算法规则进行匹配相似车辆
    随机生成临时车牌号
    无法加载 DLL“ParkCOM.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E) 终结者
    c# 除掉前三个字符,剩下的4个字符全为数字方为特殊车辆
    UI设计文本框解决Placeholder的在IE10 以下 IE 9 IE8 IE 7 的兼容问题
    EF框架 对字段属性为NULL的空值处理 类型前面加上?保证EF列表读取显示数据不会报异常
    boost::property_tree读取解析.xml文件
    C++ URLencode library
    http与中文编码传输
  • 原文地址:https://www.cnblogs.com/shirln/p/12143419.html
Copyright © 2020-2023  润新知