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

StringformatMilliseconds(final long ms)
format Milliseconds
return formatNanoseconds(ms * 1_000_000L);
StringformatMilliseconds(Double milliseconds)
Formats milliseconds in m:ss format
milliseconds /= 1000;
return String.format("%01.0f:%02.0f", milliseconds / 60, milliseconds % 60);
StringformatMilliseconds(long milliseconds)
Format milliseconds into a more readable format.
long millis = Math.round(milliseconds / (double) 1000);
StringBuffer niceString = new StringBuffer();
if (millis > 60 * 60) {
    niceString.append(millis / (60 * 60) + "h");
    millis %= (60 * 60);
if (millis > 60) {
    niceString.append(millis / (60) + "m");
...
StringformatMilliseconds(long milliseconds)
format Milliseconds
long seconds = milliseconds / 1000;
if (seconds < 60) {
    return "" + seconds + " second" + s(seconds);
long minutes = seconds / 60;
seconds = seconds % 60;
if (minutes < 60) {
    return "" + minutes + " minute" + s(minutes) + " " + seconds + " second" + s(seconds);
...
StringformatMilliSecondsHumanReadable(long x)
format Milli Seconds Human Readable
@SuppressWarnings("unused")
long millis = 0;
long seconds = 0;
long minutes = 0;
long hours = 0;
long days = 0;
seconds = (int) (x / 1000);
millis = x % 1000;
...
StringformatMillisecondsToConventional(long duration, int unitCount)
Convert milliseconds value to a human-readable duration of mixed units, using units no larger than days.
if (unitCount <= 0) {
    unitCount = 5;
if (duration == 0) {
    return "0ms";
StringBuffer sb = new StringBuffer();
if (duration < 0) {
...
StringformatMillisecondsToConventional(long time)
Convert milliseconds value to a human-readable duration
return formatMillisecondsToConventional(time, true);
StringformatMillisTime(long millis)
format Millis Time
return millisTime.get().format(new Date(millis));
StringformatMillisTimeGMT(long millis)
format Millis Time GMT
Date d = new Date(millis);
synchronized (GMT_FORMAT_MILLIS) {
    return GMT_FORMAT_MILLIS.format(d);
StringformatSystemTime(long millis)
format System Time
Date date = new Date(millis);
return DateFormat.getInstance().format(date);