Formats a date/time value as localized relative text using the Intl.RelativeTimeFormat API. Renders inside a semantic time element.
Options mirror the Intl.RelativeTimeFormat API. When unit is 'auto', the component selects the best unit based on the time difference.
<div nve-layout="column gap:sm">
<nve-format-relative-time>2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time>2024-06-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time>2025-12-01T12:00:00.000Z</nve-format-relative-time>
</div>
2020-01-15T12:00:00.000Z
2024-06-15T12:00:00.000Z
2025-12-01T12:00:00.000Z
Installation
<script type="module">
import '@nvidia-elements/core/format-relative-time/define.js';
</script>
<div nve-layout="column gap:sm">
<nve-format-relative-time>2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time>2024-06-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time>2025-12-01T12:00:00.000Z</nve-format-relative-time>
</div>
nve api.get nve-format-relative-time
By default, the component formats the date string from its text content. That text also serves as the SSR fallback. Use the date property or attribute when the value already comes from JavaScript or bound data. If both are present, date wins.
If you omit locale, the component uses document.documentElement.lang. If that value is empty, Intl.RelativeTimeFormat uses the browser default locale.
Default
Basic relative time formatting with auto unit selection. Use for displaying human-readable relative timestamps in content areas, feeds, or metadata.
<div nve-layout="column gap:sm">
<nve-format-relative-time>2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time>2024-06-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time>2025-12-01T12:00:00.000Z</nve-format-relative-time>
</div>
2020-01-15T12:00:00.000Z
2024-06-15T12:00:00.000Z
2025-12-01T12:00:00.000Z
Numeric
Numeric formatting control for natural language output. Use 'auto' to display natural forms such as 'yesterday' instead of '1 day ago'.
<div nve-layout="column gap:sm">
<nve-format-relative-time numeric="always" unit="year">2025-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time numeric="auto" unit="year">2025-01-15T12:00:00.000Z</nve-format-relative-time>
</div>
2025-01-15T12:00:00.000Z
2025-01-15T12:00:00.000Z
Format style presets for controlling output verbosity. Use 'short' or 'narrow' for compact layouts such as data tables or timelines.
<div nve-layout="column gap:sm">
<nve-format-relative-time format-style="long">2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time format-style="short">2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time format-style="narrow">2020-01-15T12:00:00.000Z</nve-format-relative-time>
</div>
2020-01-15T12:00:00.000Z
2020-01-15T12:00:00.000Z
2020-01-15T12:00:00.000Z
Unit
Explicit time unit selection for keeping relative time in a fixed unit. Use when you always want output in days, months, or years instead of letting the component auto-select the unit.
<div nve-layout="column gap:sm">
<nve-format-relative-time unit="day">2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time unit="month">2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time unit="year">2020-01-15T12:00:00.000Z</nve-format-relative-time>
</div>
2020-01-15T12:00:00.000Z
2020-01-15T12:00:00.000Z
2020-01-15T12:00:00.000Z
Locale
Explicit locale settings for internationalized relative time output. Use when the target audience locale differs from the document language or browser default.
<div nve-layout="column gap:sm">
<nve-format-relative-time locale="de-DE">2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time locale="ja">2020-01-15T12:00:00.000Z</nve-format-relative-time>
<nve-format-relative-time locale="fr-FR">2020-01-15T12:00:00.000Z</nve-format-relative-time>
</div>
2020-01-15T12:00:00.000Z
2020-01-15T12:00:00.000Z
2020-01-15T12:00:00.000Z
Date Attribute
Date attribute input for values supplied by JavaScript or bound data. By default, the component formats text content, which also serves as the SSR fallback, and date wins when both are present.
<nve-format-relative-time date="2020-01-15T12:00:00.000Z"></nve-format-relative-time>
Sync
Auto-updating relative time with the sync attribute. Use for live feeds, notifications, or dashboards where freshness matters.
<nve-format-relative-time sync>2020-01-15T12:00:00.000Z</nve-format-relative-time>
2020-01-15T12:00:00.000Z
Release Status
All elements and features go through 3 phases of stability, pre-release, beta and stable.
pre-release
Docs Preview
API Documentation
Fully Themeable
beta
Robust unit test coverages
Passed API Review
Passed Designer VQA Review
Included in library package
stable
No known outstanding AA WCAG issues
No known outstanding performance issues
Adapts to different screen/container sizes
No breaking API changes for at least 90 days