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(long time)
format Time
StringBuilder ret = new StringBuilder();
int days = (int) Math.floor(time / (1000 * 3600 * 24));
int hours = (int) Math.floor((time % (1000 * 3600 * 24)) / (1000 * 3600));
int minutes = (int) Math.floor((time % (1000 * 3600 * 24)) % (1000 * 3600) / (1000 * 60));
int seconds = (int) Math.floor(time % (1000 * 3600 * 24) % (1000 * 3600) % (1000 * 60) / 1000);
if (days != 0)
    ret.append(days + "d");
if (hours != 0 || days != 0)
...
StringformatTime(long time)
format Time
long second = (time / 1000) % 60;
long minute = (time / (1000 * 60)) % 60;
long hour = (time / (1000 * 60 * 60)) % 24;
long day = (time / (1000 * 60 * 60 * 24));
return String.format("%d Tag(e), %02d Stunde(n), %02d Minute(n) und %02d Sekunde(n)", day, hour, minute,
        second);
StringformatTime(long time)
format Time
StringBuffer buffer = new StringBuffer();
if (time < 0) {
    time = -time;
    buffer.append('-');
long millisecond = time % 1000;
time /= 1000;
long second = time % 60;
...
StringformatTime(long time)
format Time
if (time < MINUTE) {
    return (time / SECOND + " seconds"); 
} else if (time < HOUR) {
    long mn = time / MINUTE;
    return (mn + " minute(s) " + formatTime(time - (mn * MINUTE))); 
} else if (time < DAY) {
    long hours = time / HOUR;
    return (hours + " hour(s) " + formatTime(time - (hours * HOUR))); 
...
StringformatTime(long time)
format Time
if (time > MINUTE_IN_MILLIS) {
    return formatMinutes(time);
if (time > SECONDS_IN_MILLIS) {
    return formatSeconds(time);
} else {
    return formatMillis(time);
StringformatTime(long time)
Format a milisecond number.
String elapsedTime;
long seconds = time / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long sec_remainder = seconds % 60;
long min_remainder = minutes % 60;
long hours_remainder = hours % 24;
if (minutes < 1) {
...
StringformatTime(long time)
Formats time string from seconds.
StringBuffer result = new StringBuffer();
long hour = time / 3600;
time -= (hour * 3600);
long min = time / 60;
time -= (min * 60);
long sec = time;
if (hour > 0) {
    result.append(hour).append(":");
...
StringformatTime(long time)
formats a long time value into a string of the form 'ddd:hh:mm:ss'
long secsPerHour = 60 * 60;
long secsPerDay = 24 * secsPerHour;
long millis = time % 1000;
time /= 1000;
long days = time / secsPerDay;
time %= secsPerDay;
long hours = time / secsPerHour;
time %= secsPerHour;
...
StringformatTime(long time, String syntax, boolean extraZeros)
Format a timestamp to a string with days/hours/mins/secs/ms.
int days = (int) time / MSEC_IN_DAY;
time = time - days * MSEC_IN_DAY;
int hours = (int) time / MSEC_IN_HOUR;
time = time - hours * MSEC_IN_HOUR;
int mins = (int) time / MSEC_IN_MIN;
time = time - mins * MSEC_IN_MIN;
int secs = (int) time / MSEC_IN_SEC;
time = time - secs * MSEC_IN_SEC;
...
StringformatTime(long timeDiff)
Given the time in long milliseconds, returns a String in the format Xhrs, Ymins, Z sec.
StringBuffer buf = new StringBuffer();
long hours = timeDiff / (60 * 60 * 1000);
long rem = (timeDiff % (60 * 60 * 1000));
long minutes = rem / (60 * 1000);
rem = rem % (60 * 1000);
long seconds = rem / 1000;
if (hours != 0) {
    buf.append(hours);
...