Quick question, I’m not experienced in string.format() and wanna know how to format an integer value (like 5 for example) to 00:00:00 (in minutes, seconds, miliseconds).
Thanks
Quick question, I’m not experienced in string.format() and wanna know how to format an integer value (like 5 for example) to 00:00:00 (in minutes, seconds, miliseconds).
Thanks
you can use the format %02i
or %.2d
which should format a number with an extra 0 (2 = 02
, 20 = 20
). another way to do this, is with os.date()
and its format !%X
local seconds = 305 -- example value in seconds
local minutes = math.floor(seconds / 60) -- calculate the number of minutes
local remainingSeconds = seconds % 60 -- calculate the remaining seconds
local formattedTime = string.format("%02d:%02d:00", minutes, remainingSeconds)
print(formattedTime) -- output: 05:05:00
This should work fine.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.