lua格式化转换时长
发布时间:2020-12-14 22:55:46 所属栏目:大数据 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 local function string_split(str,exp)local result = {}local strlen = #strlocal index = 1while index strlen dolocal start_pos,end_pos = string
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 local function string_split(str,exp) local result = {} local strlen = #str local index = 1 while index < strlen do local start_pos,end_pos = string.find(str,exp,index) if start_pos == nil then break; else local match_str = string.sub(str,index,start_pos - 1) result[#result + 1] = match_str index = end_pos + 1 end end result[#result + 1] = string.sub(str,index) return result end local function format_time(secs,format) local format = string_split(format,":") local radix = {24,60,60} local time_str = ""; local base_value,base_name,value local i = #radix while i > 0 do base_value = radix[i] base_name = format[i + 1] value = secs % base_value if value > 0 then if base_name then time_str = value .. base_name .. time_str end end secs = math.floor(secs / base_value) i = i - 1 end if secs > 0 then time_str = secs .. format[i + 1] .. time_str end return time_str end local function main() print(format_time(math.floor(200000 / 60) * 60,"天:小时:分钟:秒")) end main() 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |