How do I fix this formatting?

Hello!

I have made a little clock, and this is the function that gets the current time.

local function formatTime(t)
	
	local t = t or tick()

	local hours = math.floor(t / 3600) % 24
	local mins = math.floor(t / 60) % 60
	local secs = t % 60

	return string.format("%d:%d:%d", hours, mins, secs)
	
end

When it hits something such as a new hour, or even day, it’ll look like this: 0:0:0.
This looks really weird, I’d like it to show 00:00:00 instead. What should I change to make this work?

return string.format("%02d:%02d:%02d", hours, mins, secs)
1 Like