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")
2 Likes

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

def ConvertSecondsToHoursMinutesSeconds(seconds):
	"""
	Copied from:
	https://www.geeksforgeeks.org/python-program-to-convert-seconds-into-hours-minutes-and-seconds/
	
	# Driver program
	n = 65244
	print(ConvertSecondsToHoursMinutesSeconds(n))
	
	18:07:24
	"""
	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.

1 Like