Java Utililty Methods Time Readable Format

List of utility methods to do Time Readable Format

Description

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

Method

StringtoTimeString(long seconds)
to Time String
long hours = seconds / 3600, remainder = seconds % 3600, minutes = remainder / 60, secs = remainder % 60;
return ((hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":"
        + (secs < 10 ? "0" : "") + secs);
StringtoTimeStringForceShowHours(long millis, boolean showSeconds, boolean showUnits)
To time string force show hours string.
int h = (int) (millis / 1000) / 3600;
int m = (int) (millis / 1000) % 3600 / 60;
int s = (int) (millis / 1000) % 60;
if (!showUnits)
    return showSeconds ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", h, m);
else
    return showSeconds ? String.format("%02dh %02dmin %02ds", h, m, s)
            : String.format("%02dh %02dmin", h, m);
...