Convert milliseconds to readable string
public class Timing {
public static double round1(double value) {
return Math.round(value * 10.0) / 10.0;
}
public static String getElapsedText(long elapsedMillis) {
if(elapsedMillis < 60000) {
double unit = round1(elapsedMillis / 1000.0);
return unit + (unit == 1 ? " second" : " seconds");
}
else if(elapsedMillis < 60000 * 60) {
double unit = round1(elapsedMillis / 60000.0);
return unit + (unit == 1 ? " minute" : " minutes");
}
else if(elapsedMillis < 60000 * 60 * 24) {
double unit = round1(elapsedMillis / (60000.0 * 60));
return unit + (unit == 1 ? " hour" : " hours");
}
else {
double unit = round1(elapsedMillis / (60000.0 * 60 * 24));
return unit + (unit == 1 ? " day" : " days");
}
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Convert:
- Convert Calendar to java.sql.Date
- Convert day of year to day of month
- Convert java.util.Date to java.sql.Time after calculation
- Convert java.util.Date to java.sql.Date after calculation
- Convert java.util.Date to java.sql.Date
- Convert Date into milliseconds
- Convert date to GMT
- Convert day of the year to date
- Convert milliseconds to readable string
- Elapsed time in hours/minutes/seconds
- Convert longs (time_t in UNIX terminology) to seconds