Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use DurationFormatUtils class to get the result in desired format?

I have a timestamp in milliseconds and I want to convert this to hours, minutes, seconds but in the below format only:

20hrs 10mins 50sec

I wanted to come up with some better format of reading the data so decided to use above one. I am using DurationFormatUtils class from Apache Commons to give me result in this format HH:mm:ss,SSS as of now:

DurationFormatUtils.formatDuration(durationForStep, "HH:mm:ss,SSS")

Is there any way I can use DurationFormatUtils class only yo get the result in my above format? If not then I think manual work will be the only other option I guess?

like image 388
user1950349 Avatar asked Oct 23 '25 04:10

user1950349


1 Answers

I haven't used this, but according to the javadoc shouldn't you be able to just do the following?

DurationFormatUtils.formatDuration(durationForStep, "HH'hrs' mm'mins' ss'sec'");
like image 53
Cinnam Avatar answered Oct 24 '25 18:10

Cinnam