Are you sure that is exactly the expression you are using? When I put 143,164 into my expression posted above, it returns 01:15:46:04
correctly.
if(
isNull(143164),
"00:00:00:00",
stringFormat(
"%02d:%02d:%02d:%02d",
toInt(floor(143164 / (24 * 3600))),
toInt(floor(143164 % (24 * 3600) / 3600)),
toInt(floor(143164 % 3600 / 60)),
toInt(floor(143164 % 60))
)
)
WAIT! You’re right. Apparently I was closing the floor() before the mathematical operations. I see this now that I copied your expression below mine. I knew I had to be missing something simple.
I swear I tried that, but I must have had something else going on. Thank you for your help!
2 Likes
Not an expression, but another option would be to do this in a script library:
from java.util import Locale
from com.inductiveautomation.ignition.common import FormatUtil
def formatTime(time):
return FormatUtil.formatDuration(Locale.getDefault(), time, FormatUtil.DurationFormatStyle.COMPACT, False)
>>> formatTime(1123311123)
u'13d 00:01:51'
>>> formatTime(1123311)
u'00:18:43'
>>> formatTime(38460)
u'00:00:38'
>>> formatTime(38460123)
u'10:41:00'
4 Likes
This worked, gave me 00:00:00
.
Thanks @Kevin.Herron
stringFormat(
"%02d:%02d:%02d",
toInt(floor({[~]Tag}/3600)),
toInt(floor({[~]Tag}%3600/60)),
toInt(floor({[~]Tag}%60)))
Edited
You’re missing the closing parenthesis for the stringFormat
function.
1 Like