Java Utililty Methods Duration Format

List of utility methods to do Duration Format

Description

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

Method

StringformatTS(long duration)
format TS
StringBuffer sb = new StringBuffer();
sb.insert(0, "ms");
sb.insert(0, duration % 1000);
duration /= 1000;
if (duration > 0) {
    sb.insert(0, "s");
    sb.insert(0, duration % 60);
    duration /= 60;
...
StringformatWordyDuration(long milliseconds)
Format a wordy time duration (e.g., "5 days, 3 hours, 23 minutes").
long seconds = milliseconds / 1000;
long days = seconds / 86400;
seconds -= days * 86400;
long hours = seconds / 3600;
seconds -= hours * 3600;
long minutes = seconds / 60;
seconds -= minutes * 60;
StringBuffer buf = new StringBuffer();
...
StringPrintDuration(long NanoSeconds)
Print Duration
long d = (long) Math.floor(NanoSeconds / (24 * 60 * 60 * 1000000000.0));
NanoSeconds -= d * 24 * 60 * 60 * 1000000000;
long h = (long) Math.floor(NanoSeconds / (60 * 60 * 1000000000.0));
NanoSeconds -= h * 60 * 60 * 1000000000;
long mn = (long) Math.floor(NanoSeconds / (60 * 1000000000.0));
NanoSeconds -= mn * 60 * 1000000000;
long s = (long) Math.floor(NanoSeconds / 1000000000.0);
NanoSeconds -= s * 1000000000;
...
StringPrintDurationConciseFromMs(long MilliSeconds)
Given a length of elapsed time represented in ms, convert to a user friendly translation into [days] [hours] minutes (hours and days only printed if necessary)
long d = (long) Math.floor(MilliSeconds / (24 * 60 * 60 * 1000.0));
MilliSeconds -= d * 24 * 60 * 60 * 1000;
long h = (long) Math.floor(MilliSeconds / (60 * 60 * 1000.0));
MilliSeconds -= h * 60 * 60 * 1000;
long mn = (long) Math.floor(MilliSeconds / (60 * 1000.0));
StringBuilder Str = new StringBuilder();
if (d != 0)
    Str.append(d).append("d");
...
StringPrintDurationMilliSeconds(long NanoSeconds)
Print Duration Milli Seconds
return F1.format(NanoSeconds / NANOSECS_PER_MILLISECOND) + "ms";