You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intl-relativetimeformat elements can be used to format relative dates and
times with language-sensitivity. You can format both past and future dates
and times. The <intl-relativetimeformat-format> and
<intl-relativetimeformat-formattoparts> elements require 2 slots for the
relative time and the unit of time. You can either use named slots (rtime
and unit) or unnamed slots (first and second <data> elements).
Example
Format a past time
<intl-relativetimeformatlocales="pt-BR" option-style="long"><p><intl-relativetimeformat-format><dataslot="rtime" value="-1">1</data><dataslot="unit" value="day">day</data>
ago
</intl-relativetimeformat-format></p></intl-relativetimeformat>
Format a future time
<intl-relativetimeformatlocales="is" option-style="long"><p><intl-relativetimeformat-format>
in
<datavalue="10">10</data><datavalue="years">years</data></intl-relativetimeformat-format></p></intl-relativetimeformat>
The slotted elements must be <data> elements with value attributes, the first slotted <data> element’s value must be a string of number that represents the relative time, the second slotted <data> element’s value must be a string that represents the unit, and it must be one of the supported unit. See more details in the MDN documentation. Alternatively, use the rtime and unit slots, which take higher precedence over the default slotted elements.
rtime
The relative time. See the default slot for more details.
unit
The unit. See the default slot for more details.
CSS Parts
Name
Description
value
The <span> element that contains the string of the formatted relative time.
The slotted elements must be <data> elements with value attributes, the first slotted <data> element’s value must be a number that represents the relative time, the second slotted <data> element’s value must be a string that represents the unit, and it must be one of the supported unit. See more details in the MDN documentation. Alternatively, use the rtime and unit slots, which take higher precedence over the default slotted elements.
rtime
The relative time. See the default slot for more details.
unit
The unit. See the default slot for more details.
CSS Parts
Name
Description
integer
The <span> element that contains the string of the formatted part which type is integer.
literal
A <span> element that contains the string of a formatted part which type is literal.
value
The <span> element that contains the elements that contain formatted parts of the given relative time and unit.