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  

Date Convert:
  1. Convert Calendar to java.sql.Date
  2. Convert day of year to day of month
  3. Convert java.util.Date to java.sql.Time after calculation
  4. Convert java.util.Date to java.sql.Date after calculation
  5. Convert java.util.Date to java.sql.Date
  6. Convert Date into milliseconds
  7. Convert date to GMT
  8. Convert day of the year to date
  9. Convert milliseconds to readable string
  10. Elapsed time in hours/minutes/seconds
  11. Convert longs (time_t in UNIX terminology) to seconds