# Display Timer Component Value in HH:MM:SS format

**URL:** <https://forum.inductiveautomation.com/t/display-timer-component-value-in-hh-mm-ss-format/9000>\
**Category:** Ignition\
**Created:** [September 4, 2014, 4:07pm UTC](https://forum.inductiveautomation.com/t/display-timer-component-value-in-hh-mm-ss-format/9000 "2014-09-04T16:07:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [September 4, 2014, 4:07pm UTC](https://forum.inductiveautomation.com/t/display-timer-component-value-in-hh-mm-ss-format/9000/1 "2014-09-04T16:07:46Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [September 4, 2014, 4:26pm UTC](https://forum.inductiveautomation.com/t/display-timer-component-value-in-hh-mm-ss-format/9000/2 "2014-09-04T16:26:44Z")

</div>

Try using [floor](https://www.inductiveautomation.com/support/usermanuals/ignition/gen_math_floor.htm):

```auto
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")
```

---

<div class="post-metadata">

**Author:** ![tony.petruzzi1](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tony.petruzzi1](https://forum.inductiveautomation.com/u/tony.petruzzi1)\
**Post date:** [May 4, 2021, 1:39pm UTC](https://forum.inductiveautomation.com/t/display-timer-component-value-in-hh-mm-ss-format/9000/3 "2021-05-04T13:39:10Z")

</div>

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 4, 2021, 2:27pm UTC](https://forum.inductiveautomation.com/t/display-timer-component-value-in-hh-mm-ss-format/9000/4 "2021-05-04T14:27:03Z")

</div>

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

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

> [@Expression tag to convert minutes to hh:mm:ss](http://forum.inductiveautomation.com/t/expression-tag-to-convert-minutes-to-hh-mm-ss/9154/10):
>
> IMO, it can just as easily be done without script. start from a date (midnight) add minutes or seconds like you want (needs to be integers, if you want high precision, you can add milliseconds as integers) format as “HH:mm:ss” This doesn’t work if the hours value can reach more than 24 hours, but apart from that, it’s quite concise and easy to understand IMO. dateFormat( addSeconds( getDate(1970,1,1), toInt({Root Container.value} \* 60) ), "HH:mm:ss" )
