How to convert seconds to format like hours/mins/secs

i made a script to tack how long the player hasnt been on my game, and it gives me seconds. so how do i turn that into a format like hours/mins/seconds? like 120 seconds gone would translate into 0/2/0

local function toHMS(s)
	return ("%02i:%02i:%02i"):format(s/60^2, s/60%60, s%60)
end

local seconds = 283
toHMS(seconds)

Basically you divide the seconds by

  • 60 for minutes
  • 60 / 60 for hours
  • 60 / 60 / 24 for days
1 Like