Most idiomatic way to print a time difference in Java?

code-formatting, datetime, idioms, java

Solution

Apache Commons has the DurationFormatUtils class for applying a specified format to a time duration. So, something like:

long time = System.currentTimeMillis();
//do something that takes some time...
long completedIn = System.currentTimeMillis() - time;

DurationFormatUtils.formatDuration(completedIn, "HH:mm:ss:SS");

Problem

I'm familiar with printing time difference in milliseconds: ``` long time = System.currentTimeMillis(); //do something that takes some time... long completedIn = System.currentTimeMillis() - time; ``` But, is there a nice way print a complete time in a specified format (eg: HH:MM:SS) either using Apache Commons or even the dreaded platform API's Date/Time objects? In other words, what is the shortest, simplest, no nonsense way to write a time format derived from milliseconds in Java?

Original source

Related problems