Class PrettyTime
Usage:
PrettyTime t = new PrettyTime();
String timestamp = t.format(new Date());
//result: moments from now
String timestamp = t.format(new Date(System.currentTimeMillis() + 1000 * 60 * 10));
//result: 10 minutes from now
- Author:
- Lincoln Baxter, III
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(String overrideResourceBundle) Create a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(Instant reference) Create a newPrettyTimeinstance that will use the givenInstanttimestamp to represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(Instant reference, String overrideResourceBundle) Create a newPrettyTimeinstance that will use the givenInstanttimestamp to represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDate reference) Create a newPrettyTimeinstance that will use the givenLocalDateand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDate reference, String overrideResourceBundle) Create a newPrettyTimeinstance that will use the givenLocalDateand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDate reference, ZoneId zoneId) Create a newPrettyTimeinstance that will use the givenLocalDateandZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDate reference, ZoneId zoneId, String overrideResourceBundle) Create a newPrettyTimeinstance that will use the givenInstanttimestamp to represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDateTime reference) Create a newPrettyTimeinstance that will use the givenLocalDateTimeand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDateTime reference, String overrideResourceBundle) Create a newPrettyTimeinstance that will use the givenLocalDateTimeand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDateTime reference, ZoneId zoneId) Create a newPrettyTimeinstance that will use the givenLocalDateTimeandZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(LocalDateTime reference, ZoneId zoneId, String overrideResourceBundle) Create a newPrettyTimeinstance that will use the givenLocalDateTimeandZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(Date reference) Create a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(Date reference, String overrideResourceBundle) Create a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting.PrettyTime(Date reference, Locale locale) Construct a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will use the givenLocaleinstead of the system default.PrettyTime(Date reference, Locale locale, String overrideResourceBundle) Construct a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will use the givenLocaleinstead of the system default.PrettyTime(Locale locale) Construct a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison.PrettyTime(Locale locale, String overrideResourceBundle) Construct a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison. -
Method Summary
Modifier and TypeMethodDescriptionapproximateDuration(Instant then) approximateDuration(LocalDate then) approximateDuration(LocalDate then, ZoneId zoneId) approximateDuration(LocalDateTime then, ZoneId zoneId) approximateDuration(Date then) calculatePreciseDuration(LocalDate then, ZoneId zoneId) Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenLocalDateTimeusing the system defaultZoneId.calculatePreciseDuration(LocalDateTime then, ZoneId zoneId) Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenLocalDateTimeusing the givenZoneId.calculatePreciseDuration(Date then) Remove all registeredTimeUnitinstances.Format the givenInstantobject.format(LocalDateTime then) Format the givenLocalDateTimeobject using the system defaultZoneId.format(LocalDateTime then, ZoneId zoneId) Format the givenLocalDateTimeobject using the givenZoneId.format(OffsetDateTime then) Format the givenOffsetDateTimeobject.format(ZonedDateTime then) Format the givenZonedDateTimeobject.Format the givenCalendarobject.Format the givenDateobject.formatDuration(Instant then) formatDuration(LocalDate then) formatDuration(LocalDate then, ZoneId zoneId) formatDuration(LocalDateTime then) Format the givenLocalDateTimeusing the system defaultZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant.formatDuration(LocalDateTime then, ZoneId zoneId) Format the givenLocalDateTimeusing the givenZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate.formatDuration(OffsetDateTime then) formatDuration(ZonedDateTime then) formatDuration(Calendar then) formatDuration(Date then) formatDuration(List<Duration> durations) formatDuration(Duration duration) formatDurationUnrounded(LocalDate then, ZoneId zoneId) Format the givenLocalDateTimeusing the system defaultZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant.formatDurationUnrounded(LocalDateTime then, ZoneId zoneId) Format the givenLocalDateTimeusing the givenZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate.Format the givenOffsetDateTimeand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant.Format the givenZonedDateTimeand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant.formatDurationUnrounded(Date then) formatDurationUnrounded(List<Duration> durations) formatDurationUnrounded(Duration duration) formatUnrounded(Instant then) Format the givenInstantobject.formatUnrounded(LocalDate then) formatUnrounded(LocalDate then, ZoneId zoneId) formatUnrounded(LocalDateTime then) Format the givenLocalDateTimeobject using the system defaultZoneId.formatUnrounded(LocalDateTime then, ZoneId zoneId) Format the givenLocalDateTimeobject using the givenZoneId.Format the givenOffsetDateTimeobject.formatUnrounded(ZonedDateTime then) Format the givenZonedDateTimeobject.formatUnrounded(Calendar then) Format the givenCalendarobject.formatUnrounded(Date then) Format the givenDateobject.formatUnrounded(List<Duration> durations) formatUnrounded(Duration duration) Get the currently configuredLocalefor thisPrettyTimeobject.<UNIT extends TimeUnit>
UNITgetUnits()registerUnit(TimeUnit unit, TimeFormat format) Register the givenTimeUnitand correspondingTimeFormatinstance to be used in calculations.<UNIT extends TimeUnit>
TimeFormatremoveUnit(Class<UNIT> unitType) Removes the mapping for the givenTimeUnittype.removeUnit(TimeUnit unit) Removes the mapping for the givenTimeUnit.Set the theLocalefor thisPrettyTimeobject.setReference(Instant timestamp) Set the referenceInstant.setReference(LocalDate localDate) setReference(LocalDate localDate, ZoneId zoneId) setReference(LocalDateTime localDateTime) setReference(LocalDateTime localDateTime, ZoneId zoneId) setReference(Date timestamp) setUnits(ResourcesTimeUnit... units) setUnits(TimeFormat format, TimeUnit... units) toString()
-
Constructor Details
-
PrettyTime
public PrettyTime()Create a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. -
PrettyTime
Create a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. Will useStringas an optional override to the default resource bundles. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenDateisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenDateisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison. Will useStringas an optional override to the default resource bundles. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenInstanttimestamp to represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenInstantisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenInstanttimestamp to represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenInstantisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. Will useStringas an optional override to the default resource bundles.- See Also:
-
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateTimeand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateTimeisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateTimeand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateTimeisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. Will useStringas an optional override to the default resource bundles.- See Also:
-
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateTimeandZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateTimeisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateTimeandZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateTimeisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. Will useStringas an optional override to the default resource bundles.- See Also:
-
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateand the system defaultZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. Will useStringas an optional override to the default resource bundles.- See Also:
-
PrettyTime
Create a newPrettyTimeinstance that will use the givenLocalDateandZoneIdto represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenLocalDateisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. -
PrettyTime
Create a newPrettyTimeinstance that will use the givenInstanttimestamp to represent the reference point forInstantcomparison, and will useLocale.getDefault()as the selectedLocalefor language and dialect formatting. If the givenInstantisnull, this instance will always use the current value ofSystem.currentTimeMillis()to represent the reference point forInstantcomparison. Will useStringas an optional override to the default resource bundles.- See Also:
-
PrettyTime
Construct a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison. This instance will use the givenLocaleinstead of the system default. If the providedLocaleisnull,Locale.getDefault()will be used. -
PrettyTime
Construct a newPrettyTimeinstance that will always use the current value ofSystem.currentTimeMillis()to represent the reference point forDatecomparison. This instance will use the givenLocaleinstead of the system default. If the providedLocaleisnull,Locale.getDefault()will be used. Will useStringas an optional override to the default resource bundles. -
PrettyTime
Construct a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will use the givenLocaleinstead of the system default.If the provided
Localeisnull,Locale.getDefault()will be used instead.
If the givenDateisnull, this instance will always use current value ofSystem.currentTimeMillis()will be used to represent the reference point forDatecomparison.See
PrettyTime#setReference(Date timestamp). -
PrettyTime
Construct a newPrettyTimeinstance that will use the givenDatetimestamp to represent the reference point forDatecomparison, and will use the givenLocaleinstead of the system default.If the provided
Localeisnull,Locale.getDefault()will be used instead.
If the givenDateisnull, this instance will always use current value ofSystem.currentTimeMillis()will be used to represent the reference point forDatecomparison. Will useStringas an optional override to the default resource bundles.See
PrettyTime#setReference(Date timestamp).
-
-
Method Details
-
approximateDuration
Calculate the approximateDurationbetween the referenceDateand givenDate. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.- See Also:
-
approximateDuration
Calculate the approximateDurationbetween the referenceInstantand givenInstant. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.- See Also:
-
approximateDuration
Calculate the approximateDurationbetween the referenceInstantand givenLocalDateTime. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- See Also:
-
approximateDuration
Calculate the approximateDurationbetween the referenceInstantand givenLocalDate. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead. -
approximateDuration
Calculate the approximateDurationbetween the referenceInstantand givenLocalDateTime. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- TheLocalDateto be compared against the reference timestamp, or now if no reference timestamp was provided- See Also:
-
approximateDuration
Calculate the approximateDurationbetween the referenceInstantand givenLocalDateTime. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead. -
calculatePreciseDuration
Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenDate. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.Note: Precision may be lost if no supplied
TimeUnitis granular enough to represent the remainder of time (in milliseconds).- Parameters:
then- TheDateto be compared against the reference timestamp, or now if no reference timestamp was provided- Returns:
- A sorted
ListofDurationobjects, from largest to smallest. Each element in the list represents the approximate duration (number of times) thatTimeUnitto fit into the previous element's delta. The first element is the largestTimeUnitto fit within the total difference between compared dates.
-
calculatePreciseDuration
Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenInstant. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.Note: Precision may be lost if no supplied
TimeUnitis granular enough to represent the remainder of time (in milliseconds).- Parameters:
then- TheInstantto be compared against the reference timestamp, or now if no reference timestamp was provided- Returns:
- A sorted
ListofDurationobjects, from largest to smallest. Each element in the list represents the approximate duration (number of times) thatTimeUnitto fit into the previous element's delta. The first element is the largestTimeUnitto fit within the total difference between compared dates.
-
calculatePreciseDuration
Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenLocalDateTimeusing the system defaultZoneId. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.Note: Precision may be lost if no supplied
TimeUnitis granular enough to represent the remainder of time (in milliseconds).- Parameters:
then- TheLocalDateTimeto be compared against the reference timestamp, or now if no reference timestamp was provided- Returns:
- A sorted
ListofDurationobjects, from largest to smallest. Each element in the list represents the approximate duration (number of times) thatTimeUnitto fit into the previous element's delta. The first element is the largestTimeUnitto fit within the total difference between compared dates.
-
calculatePreciseDuration
Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenLocalDateTimeusing the givenZoneId. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.Note: Precision may be lost if no supplied
TimeUnitis granular enough to represent the remainder of time (in milliseconds).- Parameters:
then- TheLocalDateTimeto be compared against the reference timestamp, or now if no reference timestamp was providedzoneId- TheZoneIdto be used, not null- Returns:
- A sorted
ListofDurationobjects, from largest to smallest. Each element in the list represents the approximate duration (number of times) thatTimeUnitto fit into the previous element's delta. The first element is the largestTimeUnitto fit within the total difference between compared dates.
-
calculatePreciseDuration
Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenLocalDateusing the system defaultZoneId. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.Note: Precision may be lost if no supplied
TimeUnitis granular enough to represent the remainder of time (in milliseconds).- Parameters:
then- TheLocalDateto be compared against the reference timestamp, or now if no reference timestamp was provided- Returns:
- A sorted
ListofDurationobjects, from largest to smallest. Each element in the list represents the approximate duration (number of times) thatTimeUnitto fit into the previous element's delta. The first element is the largestTimeUnitto fit within the total difference between compared dates.
-
calculatePreciseDuration
Calculate to the precision of the smallest providedTimeUnit, the exactDurationrepresented by the difference between the referenceInstantand the givenLocalDateusing the givenZoneId. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.Note: Precision may be lost if no supplied
TimeUnitis granular enough to represent the remainder of time (in milliseconds).- Parameters:
then- TheLocalDateto be compared against the reference timestamp, or now if no reference timestamp was providedzoneId- TheZoneIdto be used, not null- Returns:
- A sorted
ListofDurationobjects, from largest to smallest. Each element in the list represents the approximate duration (number of times) thatTimeUnitto fit into the previous element's delta. The first element is the largestTimeUnitto fit within the total difference between compared dates.
-
format
Format the givenDateobject. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theDateto be formatted- Returns:
- A formatted string representing
then
-
format
Format the givenCalendarobject. If the givenCalendarisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theCalendarwhose date is to be formatted- Returns:
- A formatted string representing
then
-
format
Format the givenDurationobject, using theTimeFormatspecified by theTimeUnitcontained within. If the givenDurationisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
duration- theDurationto be formatted- Returns:
- A formatted string representing
duration
-
format
Format the givenDurationobjects, using theTimeFormatspecified by theTimeUnitcontained within. Rounding rules are ignored for all but the lastDurationelement. If the givenDurationListisnullor empty, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
durations- theDurations to be formatted- Returns:
- A list of formatted strings representing
durations
-
format
Format the givenInstantobject. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theInstantto be formatted- Returns:
- A formatted string representing
then
-
format
Format the givenZonedDateTimeobject. If the givenZonedDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theZonedDateTimeto be formatted- Returns:
- A formatted string representing
then
-
format
Format the givenOffsetDateTimeobject. If the givenOffsetDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theOffsetDateTimeto be formatted- Returns:
- A formatted string representing
then
-
format
Format the givenLocalDateTimeobject using the givenZoneId. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formattedzoneId- theZoneIdto be used, not null- Returns:
- A formatted string representing
then
-
format
Format the givenLocalDateTimeobject using the system defaultZoneId. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formatted- Returns:
- A formatted string representing
then
-
format
Format the givenLocalDateobject using the givenZoneId. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
-
format
Format the givenLocalDateobject using the system defaultZoneId. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
- Parameters:
then- theLocalDateto be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenDateobject. Rounding rules are ignored. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theDateto be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenCalendarobject. This method applies theapproximateDuration(Date)method to perform its calculation. Rounding rules are ignored. If the givenCalendarisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theCalendarwhose date is to be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenDurationobject, using theTimeFormatspecified by theTimeUnitcontained within. Rounding rules are ignored. If the givenDurationisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
duration- theDurationto be formatted- Returns:
- A formatted string representing
duration
-
formatUnrounded
Format the givenDurationobjects, using theTimeFormatspecified by theTimeUnitcontained within. Rounding rules are ignored. If the givenDurationListisnullor empty, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
durations- theDurations to be formatted- Returns:
- A list of formatted strings representing
durations
-
formatUnrounded
Format the givenInstantobject. Rounding rules are ignored. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theInstantto be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenZonedDateTimeobject. Rounding rules are ignored. If the givenZonedDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theZonedDateTimeto be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenOffsetDateTimeobject. Rounding rules are ignored. If the givenOffsetDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theOffsetDateTimeto be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenLocalDateTimeobject using the givenZoneId. Rounding rules are ignored. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formattedzoneId- theZoneIdto be used, not null- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenLocalDateTimeobject using the system defaultZoneId. Rounding rules are ignored. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formatted- Returns:
- A formatted string representing
then
-
formatUnrounded
Format the givenLocalDateobject using the givenZoneId. Rounding rules are ignored. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
-
formatUnrounded
Format the givenLocalDateobject using the system defaultZoneId. Rounding rules are ignored. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
- Parameters:
then- theLocalDateto be formatted- Returns:
- A formatted string representing
then
-
formatDuration
Format the givenDateand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- the date to be formatted- Returns:
- A formatted string of the given
Date
-
formatDuration
Format the givenCalendarand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenCalendarisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- the date to be formatted- Returns:
- A formatted string of the given
Date
-
formatDuration
Format the givenDurationand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of the difference between the referenceInstantand the givenDuration. If the givenDurationisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
duration- the duration to be formatted- Returns:
- A formatted string of the given
Duration
-
formatDuration
Format the givenDurationListand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenDurationisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
durations- the durations to be formatted- Returns:
- A formatted string of the given
Duration
-
formatDuration
Format the givenInstantand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead. -
formatDuration
Format the givenInstantand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theZonedDateTimeto be formatted- Returns:
- A formatted string of the given
Instant
-
formatDuration
Format the givenInstantand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theOffsetDateTimeto be formatted- Returns:
- A formatted string of the given
Instant
-
formatDuration
Format the givenLocalDateTimeusing the givenZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formattedzoneId- theZoneIdto be used, not null- Returns:
- A formatted string of the given
LocalDateTime
-
formatDuration
Format the givenLocalDateTimeusing the system defaultZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formatted- Returns:
- A formatted string of the given
LocalDateTime
-
formatDuration
Format the givenLocalDateusing the givenZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
-
formatDuration
Format the givenLocalDateusing the system defaultZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
-
formatDurationUnrounded
Format the givenDateand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- the date to be formatted- Returns:
- A formatted string of the given
Date
-
formatDurationUnrounded
Format the givenCalendarand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenCalendarisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- the date to be formatted- Returns:
- A formatted string of the given
Date
-
formatDurationUnrounded
Format the givenDurationand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenDurationisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
duration- the duration to be formatted- Returns:
- A formatted string of the given
Duration
-
formatDurationUnrounded
Format the givenDurationListand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenDurationisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
durations- the durations to be formatted- Returns:
- A formatted string of the given
Duration
-
formatDurationUnrounded
Format the givenInstantand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenInstantisnull, the current value ofSystem.currentTimeMillis()will be used instead. -
formatDurationUnrounded
Format the givenZonedDateTimeand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theZonedDateTimeto be formatted- Returns:
- A formatted string of the given
ZonedDateTime
-
formatDurationUnrounded
Format the givenOffsetDateTimeand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenOffsetDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theOffsetDateTimeto be formatted- Returns:
- A formatted string of the given
OffsetDateTime
-
formatDurationUnrounded
Format the givenLocalDateTimeusing the givenZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate. Rounding rules are ignored. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formatted- Returns:
- A formatted string of the given
LocalDateTime
-
formatDurationUnrounded
Format the givenLocalDateTimeusing the system defaultZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceInstant. Rounding rules are ignored. If the givenLocalDateTimeisnull, the current value ofSystem.currentTimeMillis()will be used instead.- Parameters:
then- theLocalDateTimeto be formatted- Returns:
- A formatted string of the given
LocalDateTime
-
formatDurationUnrounded
Format the givenLocalDateusing the givenZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate. Rounding rules are ignored. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
-
formatDurationUnrounded
Format the givenLocalDateusing the system defaultZoneIdand return a non-relative (not decorated with past or future tense)Stringfor the approximate duration of its difference between the referenceDate. Rounding rules are ignored. If the givenLocalDateisnull, the current value ofSystem.currentTimeMillis()will be used instead.This assumes that the time of the given date is midnight.
-
getFormat
-
getReference
Get the current referenceInstant, ornullif no referenceInstantis set. SeePrettyTime.setReference(Date timestamp)- See Also:
-
getReferenceAsLegacyDate
- See Also:
-
setReference
Converts the givenDateto the referenceInstant. Ifnull,PrettyTimewill always use the current value ofSystem.currentTimeMillis()as the referenceInstant.If the
Dateformatted is before the referenceInstant, the format command will produce aStringthat is in the past tense. If theInstantformatted is after the referenceInstant, the format command will produce aStringthat is in the future tense.- See Also:
-
setReference
Set the referenceInstant. Ifnull,PrettyTimewill always use the current value ofSystem.currentTimeMillis()as the referenceInstant.If the
Instantformatted is before the referenceInstant, the format command will produce aStringthat is in the past tense. If theInstantformatted is after the referenceInstant, the format command will produce aStringthat is in the future tense. -
setReference
Converts the givenLocalDateTimeto the referenceInstantusing the system defaultZoneId. Ifnull,PrettyTimewill always use the current value ofSystem.currentTimeMillis()as the referenceInstant.If the
Instantformatted is before the referenceInstant, the format command will produce aStringthat is in the past tense. If theInstantformatted is after the referenceInstant, the format command will produce aStringthat is in the future tense.- See Also:
-
setReference
Converts the givenLocalDateTimeto the referenceInstantusing the givenZoneId. Ifnull,PrettyTimewill always use the current value ofSystem.currentTimeMillis()as the referenceInstant.If the
Instantformatted is before the referenceInstant, the format command will produce aStringthat is in the past tense. If theInstantformatted is after the referenceInstant, the format command will produce aStringthat is in the future tense.- See Also:
-
setReference
Converts the givenLocalDateto the referenceInstantusing the givenZoneId. Ifnull,PrettyTimewill always use the current value ofSystem.currentTimeMillis()as the referenceInstant.If the
Instantformatted is before the referenceInstant, the format command will produce aStringthat is in the past tense. If theInstantformatted is after the referenceInstant, the format command will produce aStringthat is in the future tense.- See Also:
-
setReference
Converts the givenLocalDateto the referenceInstantusing the givenZoneId. Ifnull,PrettyTimewill always use the current value ofSystem.currentTimeMillis()as the referenceInstant.If the
Instantformatted is before the referenceInstant, the format command will produce aStringthat is in the past tense. If theInstantformatted is after the referenceInstant, the format command will produce aStringthat is in the future tense.- See Also:
-
getUnits
-
getUnit
-
registerUnit
Register the givenTimeUnitand correspondingTimeFormatinstance to be used in calculations. If an entry already exists for the givenTimeUnit, itsTimeFormatwill be overwritten with the givenTimeFormat. (TimeUnitandTimeFormatmust not benull.) -
setUnits
-
setUnits
-
removeUnit
Removes the mapping for the givenTimeUnittype. This effectively de-registers theTimeUnitso it will not be used in formatting. Returns theTimeFormatthat was removed, ornullif no unit of the given type was registered. -
removeUnit
Removes the mapping for the givenTimeUnit. This effectively de-registers theTimeUnitso it will not be used in formatting. Returns theTimeFormatthat was removed, or null if no such unit was registered. -
getLocale
Get the currently configuredLocalefor thisPrettyTimeobject. -
setLocale
Set the theLocalefor thisPrettyTimeobject. This may be an expensive operation, since this operation callsLocaleAware.setLocale(Locale)for eachTimeUnitingetUnits(). -
toString
-
clearUnits
-