Class AmountFormats

java.lang.Object
org.threeten.extra.AmountFormats

public final class AmountFormats extends Object
Provides the ability to format a temporal amount.

This allows a TemporalAmount, such as Duration or Period, to be formatted. Only selected formatting options are provided.

Implementation Requirements:

This class is immutable and thread-safe.
  • Method Details

    • iso8601

      public static String iso8601(Period period, Duration duration)
      Formats a period and duration to a string in ISO-8601 format.

      To obtain the ISO-8601 format of a Period, Duration or PeriodDuration simply call toString().

      Parameters:
      period - the period to format
      duration - the duration to format
      Returns:
      the ISO-8601 format for the period and duration
    • wordBased

      public static String wordBased(Period period, Locale locale)
      Formats a period to a string in a localized word-based format.

      This returns a word-based format for the period. The year and month are printed as supplied unless the signs differ, in which case they are normalized. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

      Parameters:
      period - the period to format
      locale - the locale to use
      Returns:
      the localized word-based format for the period
    • wordBased

      public static String wordBased(Duration duration, Locale locale)
      Formats a duration to a string in a localized word-based format.

      This returns a word-based format for the duration. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

      Parameters:
      duration - the duration to format
      locale - the locale to use
      Returns:
      the localized word-based format for the duration
    • wordBased

      public static String wordBased(Period period, Duration duration, Locale locale)
      Formats a period and duration to a string in a localized word-based format.

      This returns a word-based format for the period. The year and month are printed as supplied unless the signs differ, in which case they are normalized. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

      Parameters:
      period - the period to format
      duration - the duration to format
      locale - the locale to use
      Returns:
      the localized word-based format for the period and duration
    • wordBased

      public static String wordBased(PeriodDuration periodDuration, Locale locale)
      Formats a period-duration to a string in a localized word-based format.

      This returns a word-based format for the period-duration. The year and month are printed as supplied unless the signs differ, in which case they are normalized. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

      Parameters:
      periodDuration - the period-duration to format
      locale - the locale to use
      Returns:
      the localized word-based format for the period-duration
      Since:
      1.9.0
    • parseUnitBasedDuration

      public static Duration parseUnitBasedDuration(CharSequence durationText)
      Parses formatted durations based on units.

      The behaviour matches the Golang duration parser, however, infinite durations are not supported.

      The duration format is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

      Note, the value "0" is specially supported as Duration.ZERO.

      Parameters:
      durationText - the formatted unit-based duration string.
      Returns:
      the Duration value represented by the string, if possible.