Premium WeedHex 636 Posted June 28, 2018 Premium Share Posted June 28, 2018 (edited) M2 Download Center This is the hidden content, please Sign In or Sign Up ( Internal ) function ToTimeFormat(seconds) local time = tonumber(seconds) if time <= 0 then return "00:00:00"; else hours = string.format("%02.f", math.floor(time/3600)); mins = string.format("%02.f", math.floor(time/60 - (hours*60))); secs = string.format("%02.f", math.floor(time - hours*3600 - mins *60)); return hours..":"..mins..":"..secs end end Without waste resources with loop or shits for exhibitionism Edited September 10, 2022 by WeedHex 17 1 1 3 7 Link to comment Share on other sites More sharing options...
Nolwarg 1 Posted June 29, 2018 Share Posted June 29, 2018 Are you Like from mpc? Link to comment Share on other sites More sharing options...
Premium WeedHex 636 Posted June 29, 2018 Author Premium Share Posted June 29, 2018 10 hours ago, Nolwarg said: Are you Like from mpc? What do you mean? Link to comment Share on other sites More sharing options...
Premium Syreldar 1886 Posted June 29, 2018 Premium Share Posted June 29, 2018 (edited) --[[ Description: Returns a string representing the total time in either the "Days, Hours, Minutes and Seconds" or "d:h:m:s" format. Arguments: sec (number): The total amount of seconds. format_type (string): Optional parameter, either "verbose" or "clock". simplify (boolean): Optional parameter, valid only if format_type is "clock". If true, the labels ("d", "h", "m", "s") will be omitted. Example: get_time_format(52165786, "verbose") -- Returns "603 days, 18 hours, 29 minutes and 46 seconds" get_time_format(52165786, "clock") -- Returns "603d:18h:29m:46s" get_time_format(52165786, "clock", true) -- Returns "603:18:29:46" Returns: string: A string representing the total time. Time complexity: O(1). Space complexity: O(1). ]] get_time_format = function(sec, format_type, simplify) format_type = format_type or "verbose"; simplify = simplify or false; local days = math.floor(sec / time_day_to_sec(1)); local hours = math.floor(math.mod(sec, time_day_to_sec(1)) / time_hour_to_sec(1)); local minutes = math.floor(math.mod(sec, time_hour_to_sec(1)) / time_min_to_sec(1)); local seconds = math.mod(sec, time_min_to_sec(1)); if (format_type == "verbose") then local parts = {}; local function add_part(quantity, unit) if (quantity > 0) then table.insert(parts, string.format("%d %s%s", quantity, unit, quantity > 1 and "s" or "")); end -- if end -- function add_part(days, "day"); add_part(hours, "hour"); add_part(minutes, "minute"); add_part(seconds, "second"); if (table.getn(parts) > 1) then parts[table.getn(parts) - 1] = string.format("%s and %s", parts[table.getn(parts) - 1], parts[table.getn(parts)]); table.remove(parts); end -- if return table.concat(parts, ", "); elseif (format_type == "clock") then if (simplify) then return string.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds); end -- if return string.format("%02dd:%02dh:%02dm:%02ds", days, hours, minutes, seconds); end -- if/elseif end -- function Edited December 28, 2023 by Syreldar Updated. 1 6 "Nothing's free in this life. Ignorant people have an obligation to make up for their ignorance by paying those who help them. Either you got the brains or cash, if you lack both you're useless." Syreldar Link to comment Share on other sites More sharing options...
Premium Syreldar 1886 Posted December 11, 2023 Premium Share Posted December 11, 2023 I have updated the function to current @ WeedHex, although you could've checked on my functions file which i constantly keep updated.. this post was almost 6 years old. This version supports clock and simplified formats. 1 "Nothing's free in this life. Ignorant people have an obligation to make up for their ignorance by paying those who help them. Either you got the brains or cash, if you lack both you're useless." Syreldar Link to comment Share on other sites More sharing options...
Recommended Posts