Skip to content

Instantly share code, notes, and snippets.

@martin-mok
Last active January 13, 2020 23:51
Show Gist options
  • Save martin-mok/07609db3d48bcd5bf5d8eaf2f1ee42b9 to your computer and use it in GitHub Desktop.
Save martin-mok/07609db3d48bcd5bf5d8eaf2f1ee42b9 to your computer and use it in GitHub Desktop.
function to convert milliseconds to HHmmss format
/**
* return HH:mm:ss format
*
* @param milliseconds time in milliseconds
* @return the string time format with HH:mm:ss
* @throws ParseException
*/
private static String getTimeFormat(long milliseconds) throws ParseException {
long totalsec = milliseconds / 1000;
long hourPart = totalsec / 3600;
long minPart = (totalsec / 60) % 60;
long secPart = totalsec % 60;
String timeFormat = null;
timeFormat = hourPart < 10 ? "0" + hourPart + ":" : hourPart + ":";
timeFormat += minPart < 10 ? "0" + minPart + ":" : minPart + ":";
timeFormat += secPart < 10 ? "0" + secPart : Long.toString(secPart);
return timeFormat;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment