Secondly, the recommendation of the JodaTime library; but I suggest toString () or the Joda ISOPeriodFormat class, as short periods (for example, 300 seconds) will display as “PT0H5M0S”, which, although correct, can disable things like (poorly written) ISO certification tests, awaiting "PT5M".
Period period = new Period(1000 * seconds); String duration1 = period.toString(); String duration2 = ISOPeriodFormat.standard().print(period);
Although I have never seen period.toString () give the wrong result, I use ISOPeriodFormat for clarity.
source share