Display Timer Component Value in HH:MM:SS format

How can I display with a label component the value of a timer component in HH:MM:SS format?
I have found the following code as a starting point, but with this I get the minutes and hours rounded up.

[code]numberFormat(toInteger({Root Container.Timer.value}/3600),“00”)

  • “:”
  • numberFormat(toInteger(({Root Container.Timer.value}%3600)/60),“00”)
  • “:”
  • numberFormat({Root Container.Timer.value}%60,“00”)[/code]

Try using floor:

numberFormat(toInteger(floor({Root Container.Timer.value}/3600.0)),"00")
+ ":"
+ numberFormat(toInteger(floor(({Root Container.Timer.value}%3600)/60.0)),"00")
+ ":"
+ numberFormat({Root Container.Timer.value}%60,"00")
1 Like

For future Googlers here is a very quick function to do this using divmod:

def ConvertSecondsToHoursMinutesSeconds(seconds):
	Copied from:
	# Driver program
	n = 65244
	min, sec = divmod(seconds, 60)
	hour, min = divmod(min, 60)
	return "%02d:%02d:%02d" % (hour, min, sec)

The original intent was to use an expression, not a script. :wink:

That said, new date functions have been added since 2014.