Formatting as time without dropping digits?

Just trying to keep a countdown timer with hours:minutes:seconds in the proper format, and have tried using:

hours = math.floor(timeuntilnext / 3600)
mins = math.floor((timeuntilnext - (hours*3600)) / 60)

secs = math.floor((timeuntilnext - (hours*3600) -(mins*60) ))

displayed with:

countdown.text = hours … “:” … mins … “:” … secs

(where timeuntilnext is the number of seconds)

Works fine, other than things turning to single digits when they’re below 10. 

How would I force the display to show a preceeding 0 in this case so seconds would show as :03 instead of :3?

Thanks!

tostring(hours)

hours = #hours < 2 and “0”…hours or hours

Another way,

countdown.text = string.format("%02d",hours) .. ":" ..string.format("%02d",mins) .. ":" ..string.format("%02d",secs) &nbsp;

or 

countdown.text =&nbsp;string.format("%02d:",hours) .. string.format("%02d:",mins) .. string.format("%02d",secs) &nbsp;

or if you want to get really fancy:

countdown.text = string.format("%02d:%02d:%02d",hours,mins,secs) &nbsp;

+1 for using string.format!

yes i thought it could be done with string.format just wasnt sure the correct pattern

Thanks guys!  Worked a charm.

tostring(hours)

hours = #hours < 2 and “0”…hours or hours

Another way,

countdown.text = string.format("%02d",hours) .. ":" ..string.format("%02d",mins) .. ":" ..string.format("%02d",secs) &nbsp;

or 

countdown.text =&nbsp;string.format("%02d:",hours) .. string.format("%02d:",mins) .. string.format("%02d",secs) &nbsp;

or if you want to get really fancy:

countdown.text = string.format("%02d:%02d:%02d",hours,mins,secs) &nbsp;

+1 for using string.format!

yes i thought it could be done with string.format just wasnt sure the correct pattern

Thanks guys!  Worked a charm.