/** * Gets the time as string with the corresponding unit. Unit can be "ms" * (for milliseconds) or "seconds". * * @param timeInMillis * the time in millis * @return the time as string * @since 1.4.2 */ public static String getTimeAsString(final double timeInMillis) { return getTimeAsString(timeInMillis, Locale.getDefault()); }
/** * Gets the time as string with the corresponding unit. Unit can be "ms" * (for milliseconds) or "seconds". * * @param timeInMillis * the time in millis * @param locale * the locale * @return the time as string * @since 1.4.2 */ public static String getTimeAsString(final double timeInMillis, final Locale locale) { if (timeInMillis > 1.0) { return getTimeAsString((long) timeInMillis); } Format nf = new DecimalFormat("#.###", new DecimalFormatSymbols(locale)); return nf.format(timeInMillis) + " ms"; }
/** * Gets the last value as time string. It returns the same result as * {@link #getLastValue()} but in a human readable format. The english * locale is used for formatting because this method is normally used for * logging (which should be normally done in English). * * @return the last time (e.g. "42 seconds") * @since 1.4.2 */ @Override public final String getLastTime() { double value = this.getLastValue(); return Converter.getTimeAsString(value, Locale.ENGLISH); }
/** * To string. * * @return the string * @see Object#toString() */ @Override public String toString() { double millis = this.getTimeInMillis(); if (millis > 6000000.0) { return super.toString(); } return Converter.getTimeAsString(millis, Locale.ENGLISH); }