To do this one, we need to create three numbers:
We also need to make sure each number is exactly two digits - e.g. 30 or 03. That way, we always get the 00:00:00 format, which will allow us to sort by duration.
So first, we need to get those counts. We won’t worry about the digit counts just yet.
floor() value which will just give us the last whole hour.floor() again.seconds % 3600 - from there, we can divide the result by 60 and get the floor()seconds % 3600, then we can get that number’s remainder by adding % 60. This will get us the remaining seconds after we’ve accounted for hours and minutes.Next, we need to account for any hour/minute/second counts that are between 0-9. For these, we need to prepend a 0 – otherwise we’d get stuff like 01:9:34. This should read 01:09:34 instead.
So after creating our number variables, we’ll create an array. Each will conditionally prepend a zero if the variable is <= 9.
Finally, we’ll call join(":") on the returned array.