Skip to content

Instantly share code, notes, and snippets.

@vincenthauser
Created August 22, 2018 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincenthauser/4fc9cff06163aa9fc019c26e6be4a097 to your computer and use it in GitHub Desktop.
Save vincenthauser/4fc9cff06163aa9fc019c26e6be4a097 to your computer and use it in GitHub Desktop.
Formatted Milliseconds
public static String msToString(long ms) {
long totalSecs = ms/1000;
long hours = (totalSecs / 3600);
long mins = (totalSecs / 60) % 60;
long secs = totalSecs % 60;
String hrsString = (hours == 0)
? "00"
: ((hours < 10)
? "0" + hours
: "" + hours);
String minsString = (mins == 0)
? "00"
: ((mins < 10)
? "0" + mins
: "" + mins);
String secsString = (secs == 0)
? "00"
: ((secs < 10)
? "0" + secs
: "" + secs);
//if (hours > 0)
return hrsString + ":" + minsString + ":" + secsString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment