# Convert milliseconds to Hour:Minute:Second format

**URL:** <https://forum.inductiveautomation.com/t/convert-milliseconds-to-hour-minute-second-format/6982>\
**Category:** Ignition\
**Created:** [August 5, 2013, 6:19pm UTC](https://forum.inductiveautomation.com/t/convert-milliseconds-to-hour-minute-second-format/6982 "2013-08-05T18:19:36Z")\
**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:** [August 5, 2013, 6:19pm UTC](https://forum.inductiveautomation.com/t/convert-milliseconds-to-hour-minute-second-format/6982/1 "2013-08-05T18:19:36Z")

</div>

I want to display the accumulated value in a timer in hour:minute:second format. Timer is in milliseconds and is an INT4 OPC tag.

---

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [August 5, 2013, 8:15pm UTC](https://forum.inductiveautomation.com/t/convert-milliseconds-to-hour-minute-second-format/6982/2 "2013-08-05T20:15:28Z")

</div>

Here’s a script I use. I’m feeding it minutes but you could feed it milliseconds and divide by 1000.  
It outputs a string in the form of HH:MM that use at the text in a label.

```auto
def GetHoursMinutesFromMinutes(MinIn) :
	# Return a string that represents HH:MM....
	try:
		Hours = MinIn // 60
		Minutes = MinIn % 60
		if Minutes < 10 :
			strMin = "0" + str(Minutes)
		else :
			strMin = str(Minutes)
		return str(Hours) + ":" + strMin
		
	except :
		return "Err"
```

---

<div class="post-metadata">

**Author:** ![njsd](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@njsd](https://forum.inductiveautomation.com/u/njsd)\
**Post date:** [August 5, 2013, 9:20pm UTC](https://forum.inductiveautomation.com/t/convert-milliseconds-to-hour-minute-second-format/6982/3 "2013-08-05T21:20:40Z")

</div>

One way to do it:

Make a label, and then tie the value to the following expression

```auto
stringFormat("%s:%s:%s",
	toInt(floor({TagPath/Timer Tag}/3600000)),
	toInt(floor(({TagPath/Timer Tag}%3600000)/60000)),
	toInt(floor(({TagPath/Timer Tag}%60000)/1000))
)
```

Not the most elegant, but it will get you there in expression language only

![](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c440064410339998ced54d08b6c9ee56b9f7f397.html)

---

<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:** [August 6, 2013, 2:39pm UTC](https://forum.inductiveautomation.com/t/convert-milliseconds-to-hour-minute-second-format/6982/4 "2013-08-06T14:39:41Z")

</div>

Thank you, from this information I was able to get a display setup.

I ended up using three LED displays with the Number Format Pattern set to :00 to display colon and leading zeros and the value expressions set as follows:

Hour: floor({TagPath/Timer Tag}/3600000)  
Minute: floor(({TagPath/Timer Tag}%3600000)/60000)  
Second: floor(({TagPath/Timer Tag}%60000)/1000)
