Java Utililty Methods Millisecond Format

List of utility methods to do Millisecond Format

Description

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

Method

StringformatMillis(Long millis)
format Millis
long seconds = millis / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
return days + " days " + hours % 24 + " hours " + minutes % 60 + " min " + seconds % 60 + " sec";
StringformatMillis(long millis)
Format ms interval to min/sec/ms
boolean isMinutes = false;
double instTime = millis;
String suffix = "milliseconds";
if (instTime > (60 * 1000)) {
    suffix = "minutes";
    instTime = instTime / (60 * 1000);
    isMinutes = true;
} else if (instTime > 1000) {
...
StringformatMillis(long millis)
Returns a formatted string using the pattern hh:mm:ss.
int hours = (int) (millis / (1000 * 60 * 60));
int minutes = (int) (millis / (1000 * 60)) % 60;
int seconds = (int) (millis / 1000) % 60;
StringBuilder sb = new StringBuilder();
if (hours > 0) {
    sb.append(hours);
    sb.append(':');
if (minutes < 10 && hours > 0) {
    sb.append(0);
sb.append(minutes);
sb.append(':');
if (seconds < 10) {
    sb.append(0);
sb.append(seconds);
return sb.toString();
StringformatMillis(long t)
format Millis
Date date = new Date(t);
return formatDate(date);
StringformatMillis(long time)
format Millis
return time + MILLIS;
StringformatMillis(long time, boolean showMillis)
format Millis
long millis = time - (1000 * (time / 1000));
time /= 1000;
long seconds = time - (60 * (time / 60));
time /= 60;
long minutes = time - (60 * (time / 60));
time /= 60;
long hours = time;
String res = hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
...
StringformatMillis(long timeMillis)
format Millis
long timeSeconds = timeMillis / 1000;
long days = timeSeconds / 60 / 60 / 24;
long hours = timeSeconds / 60 / 60 % 24;
long mins = timeSeconds / 60 % 60;
long seconds = timeSeconds % 60;
StringBuilder sb = new StringBuilder();
boolean hasDays = days > 0;
boolean hasHours = hours > 0;
...
StringformatMillis(String millisecond, String format)
format Millis
Date date;
if (format == null || "".equals(format)) {
    format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
if (millisecond != null && millisecond.matches("\\d+")) {
    date = new Date(Long.parseLong(millisecond));
    return sdf.format(date);
...
StringformatMillisAsNumber(long millis)
format Millis As Number
BigDecimal value = new BigDecimal(millis).divide(MILLIS_DIVISOR, 3, BigDecimal.ROUND_HALF_UP);
return MILLIS_NUMBER_FORMAT.format(value);
StringformatMillisAsShortHumanReadablePeriod(long millis)
Format the given milliseconds as a human readable time period
return formatMillisAsShortHumanReadablePeriod(millis, false);