Last active
January 13, 2020 23:51
-
-
Save martin-mok/07609db3d48bcd5bf5d8eaf2f1ee42b9 to your computer and use it in GitHub Desktop.
function to convert milliseconds to HHmmss format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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