Class TimeDurationFormatter


  • public class TimeDurationFormatter
    extends java.lang.Object
    Format a time duration as human-readable string, inspired by Stopwatch.toString().
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeDurationFormatter​(java.util.Locale locale, int threshold, boolean allowNonAscii)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static TimeDurationFormatter forLogging()
      Default formatter suitable for logging (ASCII-only)
      java.lang.String format​(long amount, java.util.concurrent.TimeUnit unit)
      Format the specified duration
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TimeDurationFormatter

        public TimeDurationFormatter​(java.util.Locale locale,
                                     int threshold,
                                     boolean allowNonAscii)
        Parameters:
        locale - locale for formatting (affects the decimal point)
        threshold - integral value that needs to be exceeded to switch to a certain time unit for display (e.g., specify 2 to switch to 'days' when the elapsed time is two or more days.
        allowNonAscii - set to true if the display unit can use the non-ASCII "micro" Unicode character
    • Method Detail

      • forLogging

        public static TimeDurationFormatter forLogging()
        Default formatter suitable for logging (ASCII-only)
      • format

        public java.lang.String format​(long amount,
                                       java.util.concurrent.TimeUnit unit)
        Format the specified duration
        Parameters:
        amount - number of time units
        unit - time unit