public abstract class SimpleDurationFormat extends Object implements Serializable
SimpleDurationFormat is a class for formatting human-readable, localized
duration information.
In order to improve readability, the leading (i.e. most significant) time unit has typically value greater than 1:
| Duration in seconds | Typical formatted representation |
|---|---|
| 59 | 59 seconds |
| 60 | 60 seconds |
| 61 | 61 seconds |
| 119 | 119 seconds |
| 120 | 2 minutes |
| 121 | 2 minutes 1 second |
| Modifier and Type | Field and Description |
|---|---|
protected static Map<TimeUnit,String> |
LABEL_BY_UNIT |
| Modifier | Constructor and Description |
|---|---|
protected |
SimpleDurationFormat()
The default constructor has
protected visibility |
| Modifier and Type | Method and Description |
|---|---|
static SimpleDurationFormat |
getInstance()
Obtains an instance of
SimpleDurationFormat for the default locale. |
static SimpleDurationFormat |
getInstance(Locale locale)
Obtains an instance of
SimpleDurationFormat for the provided locale. |
static SimpleDurationFormat |
getLanguageNeutralInstance()
Obtains an instance of
SimpleDurationFormat for the "undefined" locale,
specified in JDK by an "und" language tag. |
String |
toHumanDuration(long millis)
Returns the duration specified in milliseconds in the appropriate
human-readable representation.
|
abstract Appendable |
toHumanDuration(long millis,
Appendable target)
Translates the duration specified in milliseconds to the appropriate
human-readable representation and appends it to the
target. |
String |
toHumanDuration(long duration,
TimeUnit unit)
Returns the duration specified in milliseconds in the appropriate
human-readable representation.
|
Appendable |
toHumanDuration(long duration,
TimeUnit unit,
Appendable target)
Translates the duration specified in an arbitrary time unit to the appropriate
human-readable representation and appends it to the
target. |
abstract Appendable |
toHumanDurationSafe(long millis,
Appendable target)
Translates the duration specified in milliseconds to the appropriate
human-readable representation and appends it to the
target. |
Appendable |
toHumanDurationSafe(long duration,
TimeUnit unit,
Appendable target)
Translates the duration specified in an arbitrary time unit to the appropriate
human-readable representation and appends it to the
target. |
protected SimpleDurationFormat()
protected visibilitypublic static SimpleDurationFormat getInstance()
SimpleDurationFormat for the default locale.Locale.getDefault()public static SimpleDurationFormat getLanguageNeutralInstance()
SimpleDurationFormat for the "undefined" locale,
specified in JDK by an "und" language tag.Locale.forLanguageTag(String)public static SimpleDurationFormat getInstance(Locale locale)
SimpleDurationFormat for the provided locale.
If no localization data for the given locale are found, the normal fall-back
mechanism of ResourceBundle is applied.locale - the localeNullPointerException - if locale is nullpublic abstract Appendable toHumanDuration(long millis, Appendable target) throws IOException
target.
If the checked IOException is deemed unnecessary (e.g. while
appending to a StringBuilder), the sibling method
toHumanDurationSafe(long, Appendable) may be more appropriate.
millis - duration given in millisecondstarget - object to which the formatted duration is appendedtarget referenceNullPointerException - if target is nullIllegalArgumentException - if millis is negativeIOException - if appending to the target caused an errorpublic abstract Appendable toHumanDurationSafe(long millis, Appendable target)
target.
This method differs from toHumanDuration(long, Appendable)
in that the potential IOException is suppressed (and omitted
from method signature).
millis - duration given in millisecondstarget - object to which the formatted duration is appendedtarget referenceNullPointerException - if target is nullIllegalArgumentException - if millis is negativepublic final String toHumanDuration(long millis)
millis - duration given in millisecondsIllegalArgumentException - if millis is negativepublic final Appendable toHumanDuration(long duration, TimeUnit unit, Appendable target) throws IOException
target.
If the checked IOException is deemed unnecessary (e.g. while
appending to a StringBuilder), the sibling method
toHumanDurationSafe(long, java.util.concurrent.TimeUnit, Appendable)
may be more appropriate.
duration - duration given in unit time unitunit - time unittarget - object to which the formatted duration is appendedtarget referenceNullPointerException - if unit or target is nullIllegalArgumentException - if duration is negativeIOException - if appending to the target caused an errorpublic final Appendable toHumanDurationSafe(long duration, TimeUnit unit, Appendable target)
target.
This method differs from toHumanDuration(long, java.util.concurrent.TimeUnit, Appendable)
in that the potential IOException is suppressed (and omitted from method
signature).
duration - duration given in unit time unitunit - time unittarget - object to which the formatted duration is appendedtarget referenceNullPointerException - if unit or target is nullIllegalArgumentException - if duration is negativepublic final String toHumanDuration(long duration, TimeUnit unit)
duration - duration given in unit time unitunit - time unitIllegalArgumentException - if duration is negativeCopyright © 2014 Boleslav Bobcik - Auderis. All rights reserved.