Convert milliseconds to HH:MM:SS

This should be an easy one for the community, but it’s driving me nuts. I have code that creates elapse time in milliseconds. I need to convert that to a HH:MM:SS string with leading zeros. For the life of me I can’t figure out how to get this done. Any help would be greatly appreciated.

You probably want this class:

And for actual date/time conversions:

Russ_Thomas,
Thanks for your reply but I found another answer. What I needed was to format elapse time in HH.mm.ss.SSS with leading zeros, (i.e., 00:00:53.394). I found the “DurationFormatUtils” module that worked for me:

import org.apache.commons.lang.time.DurationFormatUtils as DurationFormatUtils
long timeTaken = 53394
KeywordUtil.logInfo('Time split: ’ + DurationFormatUtils.formatDuration(timeTaken, ‘HH:mm:ss.SSS’, true))

Output: Time split: 00:00:53.394

And this got me what I needed.

1 Like