Java Utililty Methods Millisecond Convert

List of utility methods to do Millisecond Convert

Description

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

Method

StringmillisToText(long millis)
Convert time to a string
return millisToString(millis, true);
StringmillisToTime(final long time)
millis To Time
String format = String.format("%%0%dd", 2);
long elapsedTime = time / 1000;
String seconds = String.format(format, elapsedTime % 60);
String minutes = String.format(format, (elapsedTime % 3600) / 60);
String hours = String.format(format, elapsedTime / 3600);
String output = hours + ":" + minutes + ":" + seconds;
return output;
StringmillisToTime(float millis)
millis To Time
float secs = millis / 1000;
int mins = (int) (secs / 60);
secs -= mins * 60;
secs = roundToAccuracy(secs, 0.1F);
String time = mins + ":" + secs;
if (time.length() > time.lastIndexOf('.') + 2) { 
    time = time.substring(0, time.lastIndexOf('.') + 2);
return time;
StringmillisToTime(long ms)
milliseconds to day hour:min:ss
int ss = 1000;
int mi = ss * 60;
int hh = mi * 60;
int dd = hh * 24;
long day = ms / dd;
long hour = (ms - day * dd) / hh;
long minute = (ms - day * dd - hour * hh) / mi;
long second = (ms - day * dd - hour * hh - minute * mi) / ss;
...
StringmillisToTimeSpan(final long interv)
Convert the input argument into a string describing the time span.
StringBuffer buf = new StringBuffer(100);
long lMillis = interv;
if (lMillis <= 0L) {
    buf.append("0 seconds");
    return buf.toString();
final long lYears = (long) (lMillis / MSECS_PER_YEAR);
lMillis = lMillis % MSECS_PER_YEAR;
...
StringmillisToTimeSpan(long millis)
millis To Time Span
if (millis < 60 * 1000) {
    long unit = roundUp(millis / 1000);
    return unit + (unit == 1 ? " second" : " seconds");
} else if (millis < 60 * 1000 * 60) {
    long unit = roundUp(millis / 60000);
    return unit + (unit == 1 ? " minute" : " minutes");
} else if (millis < 60 * 1000 * 60 * 24) {
    long unit = roundUp(millis / (60000 * 60));
...
StringMillisToTimeString(long millis)
Millis To Time String
int hours, minutes, seconds;
float timeValue = millis / 3600000.0f;
hours = (int) Math.floor(timeValue);
minutes = (int) Math.floor((timeValue - hours) * 60);
seconds = (int) Math.round((timeValue - hours - (minutes / 60.0f)) * 3600);
if (seconds >= 60) {
    seconds -= 60;
    minutes += 1;
...
StringmillisToWords(long millis)
millis To Words
double dhrs = (millis / (double) (3600000));
double dmin = (dhrs - Math.floor(dhrs)) * 60;
double dsec = (dmin - Math.floor(dmin)) * 60;
int hrs = (int) dhrs;
int min = (int) dmin;
int sec = (int) dsec;
return (hrs > 0 ? (hrs + (" hour" + (hrs > 1 ? "s " : " "))) : "") + (min > 0 ? min + " minutes " : "")
        + (sec + " seconds");
...
longtoMillis(int seconds)
to Millis
return ((long) seconds) * 1000;
longtoMillis(int timeInSecs)
Converts seconds to milliseconds, with a precision of 1 second
return timeInSecs * ONE_SECOND;