Java Utililty Methods Time Format

List of utility methods to do Time Format

Description

The list of methods to do Time Format are organized into topic(s).

Method

StringformatInformalTime(final String minuteRoundedName, final String minuteRoundingToken, final String informalHourName)
Generate nicely formatted conversational / informal time string, intelligently dealing with whitespace.
String informalTime;
if ("".equals(minuteRoundedName)) {
    informalTime = minuteRoundingToken + informalHourName;
} else {
    informalTime = minuteRoundingToken + minuteRoundedName + " " + informalHourName;
return informalTime;
StringformatMeasures(final int quartersPerMeasure, final double time, final int startOffset)
Format the given time as measure.quarters.eights.
final int measure = (int) Math.floor(time / quartersPerMeasure);
double t = time - measure * quartersPerMeasure;
final int quarters = (int) Math.floor(t); 
t = t - quarters; 
final int eights = (int) Math.floor(t / 0.25);
return measure + startOffset + "." + (quarters + startOffset) + "." + (eights + startOffset);
StringformatMicroSpan(long time)
format Micro Span
long timeHigh = time / 1000L;
long timeLow = time % 1000L;
return String.format("%d.%03d", timeHigh, timeLow);
StringformatMili(long timeDelta)
format Mili
if (timeDelta < 1000) {
    return "" + timeDelta + " miliseconds";
} else if (timeDelta < 60000) {
    return "" + (double) timeDelta / 1000.0 + " seconds";
} else if (timeDelta < 3600000) {
    return "" + (double) timeDelta / 60000.0 + " minutes";
} else {
    return "" + (double) timeDelta / 3600000.0 + " hours";
...
StringformatMs(long elapsedTime)
format Ms
String format = String.format("%%0%dd", 2);
String ms = String.format(format, elapsedTime % 1000);
elapsedTime = elapsedTime / 1000;
String seconds = String.format(format, elapsedTime % 60);
String minutes = String.format(format, (elapsedTime % 3600) / 60);
String hours = String.format(format, elapsedTime / 3600);
String time = hours + ":" + minutes + ":" + seconds + ":" + ms;
return time;
...
StringformatMusicTime(int time)
format Music Time
String string;
if (time < 10) {
    string = "0" + time;
} else {
    string = String.valueOf(time);
return string;
StringformatNanosec(long timeNanosec)
format Nanosec
if (timeNanosec < 10 * SEC_IN_NANOSEC)
    return String.format("%10.2f", timeNanosec / MILLISEC_IN_NANOSEC) + " msec";
if (timeNanosec < 10 * MIN_IN_NANOSEC)
    return String.format("%10.2f", timeNanosec / SEC_IN_NANOSEC) + " sec";
if (timeNanosec < 10 * HOUR_IN_NANOSEC)
    return String.format("%10.2f", timeNanosec / MIN_IN_NANOSEC) + " min";
if (timeNanosec < 10 * DAY_IN_NANOSEC)
    return String.format("%10.2f", timeNanosec / HOUR_IN_NANOSEC) + " hour";
...
StringformatPeroid(long time)
format Peroid
long seconds = time / 1000;
long s = seconds % 60;
long m = (seconds / 60) % 60;
long h = seconds / 60 / 60;
return String.format("%02d:%02d:%02d", h, m, s);
StringformatRemainingTime(float seccounds)
format Remaining Time
return formatRemainingTime(seccounds, false);
StringformatRuntime(long runtime)
Formats a runtime in the format hh:mm:ss, to be used e.g.
long seconds = (runtime / SECONDS) % 60;
long minutes = (runtime / MINUTES) % 60;
long hours = (runtime / HOURS) % 24;
long days = runtime / DAYS;
StringBuffer strBuf = new StringBuffer();
if (days > 0) {
    if (days < 10) {
        strBuf.append('0');
...