Period formatting is performed by the {@link PeriodFormatter} class.Three classes provide factory methods to create formatters, and this is one. The others are {@link PeriodFormat} and {@link ISOPeriodFormat}.
PeriodFormatterBuilder is used for constructing formatters which are then used to print or parse. The formatters are built by appending specific fields or other formatters to an instance of this builder.
For example, a formatter that prints years and months, like "15 years and 8 months", can be constructed as follows:
PeriodFormatter yearsAndMonths = new PeriodFormatterBuilder() .printZeroAlways() .appendYears() .appendSuffix(" year", " years") .appendSeparator(" and ") .printZeroRarely() .appendMonths() .appendSuffix(" month", " months") .toFormatter();
PeriodFormatterBuilder itself is mutable and not thread-safe, but the formatters that it builds are thread-safe and immutable. @author Brian S O'Neill @since 1.0 @see PeriodFormat
|
|