Here you can find the source of prettyPrintTime(long millis)
Parameter | Description |
---|---|
millis | time in millis |
public static String prettyPrintTime(long millis)
//package com.java2s; //License from project: Apache License import java.text.NumberFormat; import java.util.concurrent.TimeUnit; public class Main { public static String prettyPrintTime(long time, TimeUnit unit) { return prettyPrintTime(unit.toMillis(time)); }//from w ww. j a v a 2 s .c o m /** * Prints a time for display * * @param millis time in millis * @return the time, represented as millis, seconds, minutes or hours as appropriate, with suffix */ public static String prettyPrintTime(long millis) { if (millis < 1000) return millis + " milliseconds"; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); double toPrint = ((double) millis) / 1000; if (toPrint < 300) { return nf.format(toPrint) + " seconds"; } toPrint = toPrint / 60; if (toPrint < 120) { return nf.format(toPrint) + " minutes"; } toPrint = toPrint / 60; return nf.format(toPrint) + " hours"; } }