Java Utililty Methods Second Format

List of utility methods to do Second Format

Description

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

Method

StringformatSeconds(long millis)
Formats the given long to X hour, Y min, Z sec.
long[] values = new long[4];
values[0] = millis / MILLIS_PER_DAY;
values[1] = (millis / MILLIS_PER_HOUR) % 24;
values[2] = (millis / MILLIS_PER_MINUTE) % 60;
values[3] = (millis / MILLIS_PER_SECOND) % 60;
String[] fields = { " d ", " h ", " min ", " sec" };
StringBuffer buf = new StringBuffer(64);
boolean valueOutput = false;
...
StringformatSeconds(long s, boolean letters)
format Seconds
String string = "";
if (s < 1)
    return "00:00";
long remainder;
long days = (int) s / 86400;
long hours = (int) (s % 86400) / 3600;
remainder = s - days * 86400 - hours * 3600;
long mins = (int) remainder / 60;
...
StringformatSeconds(long seconds)
Formats a number of seconds to hours, minutes and seconds.
StringBuilder sb = new StringBuilder();
long hours = seconds / (3600);
if (hours > 0) {
    sb.append(hours + " h");
long secondsRemaining = seconds % (3600);
long minutes = secondsRemaining / 60;
if (minutes > 0) {
...
StringformatSeconds(long seconds)
format Seconds
long d = seconds / 3600 / 24;
long h = (seconds / 3600) % 24;
long m = (seconds / 60) % 60;
long s = seconds % 60;
if (d > 0)
    return d + "d" + h + "h" + m + "m" + s + "s";
if (h > 0)
    return h + "h" + m + "m" + s + "s";
...
StringformatSeconds(long secsIn)
format Seconds
long hours = secsIn / 3600,
        remainder = secsIn % 3600, minutes = remainder / 60, seconds = remainder % 60;
String displayhours = hours == 0 ? "" : hours + " hour" + getPlural(hours);
String displayMin = minutes == 0 ? "" : minutes + " minut" + getPlural(minutes);
String displaySec = seconds == 0 ? "" : seconds + " second" + getPlural(seconds);
return displayhours + displayMin + displaySec;
StringformatSeconds(long time)
format Seconds
long kbsize = Math.round((float) time / SECONDS_IN_MILLIS); 
return String.valueOf(kbsize) + SECONDS;
StringformatSeconds(long time)
format Seconds
if (time == Long.MAX_VALUE) {
    return "DNF";
String sign = "";
if (time < 0) {
    sign = "-";
    time = -time;
time = (time + 5) / 10;
long seconds = time / 100;
long centiseconds = time % 100;
return sign + seconds + "." + (centiseconds < 10 ? "0" + centiseconds : centiseconds);
StringformatSeconds(long time, String timerPrecisionId, boolean round)
format Seconds
String result = "";
if (time == Long.MAX_VALUE) {
    return "DNF";
String sign = "";
if (time < 0) {
    sign = "-";
    time = -time;
...
StringformatSecondsRegular(int seconds)
format Seconds Regular
int sec = seconds % 60;
int min = seconds / 60 % 60;
int h = seconds / 3600;
return ((h != 0) ? h + " h " : "") + ((min != 0) ? min + " min" : sec + " s");
StringformatSecondsWithHour(int seconds)
format seconds in hh:mm:ss format
int hours = seconds / 3600;
int minutes = (seconds % 3600) / 60;
seconds = seconds % 60;
return hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;