Milliseconds to Hour:Minutes:Seconds format (double digits)

Thanks to njsd on a post in another topic, I found this solution to converting milliseconds to Hours:Minutes:Seconds via an expression. It works very well (Thanks njsd) :prayer: .

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

[color=#0000FF]
Code:
stringFormat("%s:%s:%s",
toInt(floor({TagPath/Timer Tag}/3600000)),
toInt(floor(({TagPath/Timer Tag}%3600000)/60000)),
toInt(floor(({TagPath/Timer Tag}%60000)/1000))
)
[/color]

Is there a way to force the string format to always show two digits per segment? For example, when either the hours, minutes or seconds values are single digit values you get something like this: 12:1:0.

I would prefer 12:01:00.

Any assistance would be greatly appreciated.

Use this:

stringFormat("%d:%02d:%02d", toInt(floor({TagPath/Timer Tag}/3600000)), toInt(floor(({TagPath/Timer Tag}%3600000)/60000)), toInt(floor(({TagPath/Timer Tag}%60000)/1000)) )
Cheers,

3 Likes

Didn;'t work for me. I am trying to use a numeric label and bind the expression to the one that you mentioned!

You can’t use a numeric label because the expression gives you a string, not a number. Try a regular label instead.