Interface RelativeTimeFormat
interface RelativeTimeFormat {
format(value: number, unit: RelativeTimeFormatUnit): string;
formatToParts(value: number, unit: RelativeTimeFormatUnit): RelativeTimeFormatPart[];
resolvedOptions(): ResolvedRelativeTimeFormatOptions;
}
format(value: number, unit: RelativeTimeFormatUnit): string;
formatToParts(value: number, unit: RelativeTimeFormatUnit): RelativeTimeFormatPart[];
resolvedOptions(): ResolvedRelativeTimeFormatOptions;
}
Index
Methods
Methods
format
- format(value, unit): string
Parameters
- value: number
Numeric value to use in the internationalized relative time message
- unit: RelativeTimeFormatUnit
Unit to use in the relative time internationalized message.
Returns string
Internationalized relative time message as string
MDN.
- value: number
formatToParts
- format
To (value, unit): RelativeTimeFormatPart[]Parts Returns an array of objects representing the relative time format in parts that can be used for custom locale-aware formatting.
Parameters
- value: number
Numeric value to use in the internationalized relative time message
- unit: RelativeTimeFormatUnit
Unit to use in the relative time internationalized message.
Returns RelativeTimeFormatPart[]
- value: number
resolvedOptions
- resolved
Options (): ResolvedRelativeTimeFormatOptions Provides access to the locale and options computed during initialization of this
Intl.RelativeTimeFormat
object.MDN.
Returns ResolvedRelativeTimeFormatOptions
Formats a value and a unit according to the locale and formatting options of the given
Intl.RelativeTimeFormat
object.While this method automatically provides the correct plural forms, the grammatical form is otherwise as neutral as possible.
It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week". This API does not support relative dates involving compound units. e.g "in 5 days and 4 hours".