Convert seconds value to hours minutes seconds?

Is it necessary to use a BigDecimal? If you don’t have to, I’d use an int or long for seconds, and it would simplify things a little bit:

hours = totalSecs / 3600;
minutes = (totalSecs % 3600) / 60;
seconds = totalSecs % 60;

timeString = String.format("%02d:%02d:%02d", hours, minutes, seconds);

You might want to pad each to make sure they’re two digit values(or whatever) in the string, though.

Leave a Comment