Package com.ibm.icu.impl.duration
Interface DurationFormatter
-
- All Known Implementing Classes:
BasicDurationFormatter
public interface DurationFormatter
Formatter for durations in milliseconds.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
formatDurationFrom(long duration, long referenceDate)
Formats a duration expressed in milliseconds from a reference date.java.lang.String
formatDurationFromNow(long duration)
Formats a duration expressed in milliseconds.java.lang.String
formatDurationFromNowTo(java.util.Date targetDate)
Formats the duration between now and a target date.DurationFormatter
withLocale(java.lang.String localeName)
Returns a new DurationFormatter that's the same as this one but formats for a new locale.DurationFormatter
withTimeZone(java.util.TimeZone tz)
Returns a new DurationFormatter that's the same as this one but uses a different time zone.
-
-
-
Method Detail
-
formatDurationFromNowTo
java.lang.String formatDurationFromNowTo(java.util.Date targetDate)
Formats the duration between now and a target date.This is a convenience method that calls formatDurationFrom(long, long) using now as the reference date, and the difference between now and
targetDate.getTime()
as the duration.- Parameters:
targetDate
- the ending date- Returns:
- the formatted time
-
formatDurationFromNow
java.lang.String formatDurationFromNow(long duration)
Formats a duration expressed in milliseconds.This is a convenience method that calls formatDurationFrom using the current system time as the reference date.
- Parameters:
duration
- the duration in millisecondstz
- the time zone- Returns:
- the formatted time
-
formatDurationFrom
java.lang.String formatDurationFrom(long duration, long referenceDate)
Formats a duration expressed in milliseconds from a reference date.The reference date allows formatters to use actual durations of variable-length periods (like months) if they wish.
The duration is expressed as the number of milliseconds in the past (negative values) or future (positive values) with respect to a reference date (expressed as milliseconds in epoch).
- Parameters:
duration
- the duration in millisecondsreferenceDate
- the date from which to compute the duration- Returns:
- the formatted time
-
withLocale
DurationFormatter withLocale(java.lang.String localeName)
Returns a new DurationFormatter that's the same as this one but formats for a new locale.- Parameters:
localeName
- the name of the new locale- Returns:
- a new formatter for the given locale
-
withTimeZone
DurationFormatter withTimeZone(java.util.TimeZone tz)
Returns a new DurationFormatter that's the same as this one but uses a different time zone.- Parameters:
tz
- the time zone in which to compute durations.- Returns:
- a new formatter for the given locale
-
-