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

StringformatTime(int seconds)
format Time
if (seconds >= 3600) {
    return (seconds / 3600) + ":" + ((seconds % 3600) <= 9 ? "0" + (seconds % 3600) + ":" + (seconds - 3600)
            : (seconds % 3600) + ":" + (seconds - 3600));
} else if (seconds >= 60) {
    return (seconds / 60 + ":" + ((seconds % 60) <= 9 ? "0" + (seconds % 60) : (seconds % 60)));
} else {
    return seconds + "";
StringformatTime(int seconds)
Formats the time information as a string.
StringBuilder result = new StringBuilder();
int days, hrs, mins, secs;
days = seconds / (60 * 60 * 24);
seconds %= 60 * 60 * 24;
hrs = seconds / (60 * 60);
seconds %= 60 * 60;
mins = seconds / 60;
secs = seconds % 60;
...
StringformatTime(int secs)
format Time
String minutes = String.valueOf(secs / 60);
String seconds = String.valueOf(secs % 60);
if (secs % 60 < 10) {
    seconds = "0" + seconds;
if (secs % 60 == 0) {
    seconds = "00";
return minutes + ":" + seconds;
StringformatTime(int time)
format Time
int seconds = time % 60;
time /= 60;
int minutes = time % 60;
time /= 60;
int hours = time % 24;
time /= 24;
int days = time;
return String.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds);
...
StringformatTime(int time)
format Time
int hours = time / SECONDS_PER_HOUR;
int minutes = (time - hours * SECONDS_PER_HOUR) / MINUTES_PER_HOUR;
int seconds = time % SECONDS_PER_MINUTE;
if (hours == 0)
    return padz(minutes + "", 2) + ":" + padz(seconds + "", 2);
return hours + "h" + padz(minutes + "", 2);
StringformatTime(int time)
format Time
int seconds = (int) Math.ceil((time % 6000) / 100.0);
int minutes = time / 6000;
if (seconds == 60) {
    seconds = 0;
    minutes++;
return String.format("%02d:%02d", minutes, seconds);
StringformatTime(int time)
Method formatTime.
if (time == 0) {
    return "now";
time = Math.abs(time);
String ret = "";
long numDays = time / 86400;
time -= numDays * 86400;
long numHours = time / 3600;
...
StringformatTime(int time)
format Time
if (time < 10) {
    return 0 + String.valueOf(time);
} else {
    return String.valueOf(time);
StringformatTime(int value)
format Time
return value < 10 ? "0" + value : "" + value;
StringformatTime(Integer hour, Integer minute, Integer second, Integer ampm, Integer zoneOffset)
format Time
final StringBuilder result = new StringBuilder();
int hour24 = (hour == null) ? 0 : hour.intValue();
if (ampm != null) {
    hour24 %= 12;
    if (ampm == 1)
        hour24 += 12;
result.append(asDigits(hour24, 2)).append(':').append(minute == null ? "00" : asDigits(minute, 2));
...