public final class DurationFormatter extends Object
Modifier and Type | Field and Description |
---|---|
static DurationFormatter |
COMPACT
Example: 5D18h1m23s
|
static DurationFormatter |
FULL
Example: 5 days 18 hours 1 minute 23 seconds
|
Constructor and Description |
---|
DurationFormatter()
Creates a duration with the default locale and full words for
duration units.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
String |
format(Duration duration)
Formats the given duration to a string.
|
String |
format(long duration)
Formats the given duration (in milliseconds) to a string.
|
DurationUnit |
getHighestUnit() |
String |
getInnerSeparator() |
Locale |
getLocale() |
DurationUnit |
getLowestUnit() |
NumberFormat |
getNumberFormat() |
String |
getOuterLastSeparator() |
String |
getOuterSeparator() |
IDurationUnitFormatter |
getUnitFormatter() |
int |
getUnitPrecision() |
int |
hashCode() |
String |
toString() |
DurationFormatter |
withHighestUnit(DurationUnit highestUnit)
Creates a copy if this formatter with the given highest unit.
|
DurationFormatter |
withInnerSeparator(String innerSeparator)
Creates a copy if this formatter with the specified separator text
to be inserted between the numeric and textual values.
|
DurationFormatter |
withLocale(Locale locale)
Creates a copy if this formatter with the given locale.
|
DurationFormatter |
withLowestUnit(DurationUnit lowestUnit)
Creates a copy if this formatter with the given lowest unit.
|
DurationFormatter |
withNumberFormat(NumberFormat numberFormat)
Creates a copy if this formatter with the given number format.
|
DurationFormatter |
withOuterLastSeparator(String outerLastSeparator)
Creates a copy if this formatter with the specified separator text
to be inserted between the second to last and last formatter units
(number and text pairs).
|
DurationFormatter |
withOuterSeparator(String outerSeparator)
Creates a copy if this formatter with the specified separator text
to be inserted between each formatter units (number and text pairs).
|
DurationFormatter |
withUnitFormatter(IDurationUnitFormatter unitFormatter)
Creates a copy if this formatter with the given unit formatter.
|
DurationFormatter |
withUnitPrecision(int unitPrecision)
Creates a copy if this formatter with the given unit precision.
|
public static final DurationFormatter COMPACT
public static final DurationFormatter FULL
public DurationFormatter()
public DurationFormatter withLocale(Locale locale)
locale
- localepublic Locale getLocale()
public DurationFormatter withUnitPrecision(int unitPrecision)
unitPrecision
- unit precisionpublic int getUnitPrecision()
public DurationFormatter withNumberFormat(NumberFormat numberFormat)
RBDurationUnitFormatter.FULL
.numberFormat
- number formatpublic NumberFormat getNumberFormat()
public DurationFormatter withHighestUnit(DurationUnit highestUnit)
highestUnit
- highest unitpublic DurationUnit getHighestUnit()
public DurationFormatter withLowestUnit(DurationUnit lowestUnit)
lowestUnit
- lowest unitpublic DurationUnit getLowestUnit()
public DurationFormatter withUnitFormatter(IDurationUnitFormatter unitFormatter)
unitFormatter
- unit formatterpublic IDurationUnitFormatter getUnitFormatter()
public DurationFormatter withInnerSeparator(String innerSeparator)
10-seconds
. Default is a single space character.innerSeparator
- inner separatorpublic String getInnerSeparator()
public DurationFormatter withOuterSeparator(String outerSeparator)
2 minutes, 10 seconds
.
Default is a single space character.outerSeparator
- outer separatorpublic String getOuterSeparator()
public DurationFormatter withOuterLastSeparator(String outerLastSeparator)
1 hour 2 minutes and 10 seconds
.
Default is null
(fallsback to
using getOuterSeparator()
).outerLastSeparator
- last outer separatorpublic String getOuterLastSeparator()
public String format(Duration duration)
duration
- the duration to formatpublic String format(long duration)
duration
- the duration to formatCopyright © 2008–2023 Norconex Inc.. All rights reserved.