Relative Time
formatRelative() and formatInstant() on Date + Intl, a RelativeTime <time> with the absolute instant in its title, and a useNow hook that pauses while the page is hidden.
Example
- Updated (UTC)
- Actualizado (Madrid)
relative-time-demo.tsxCopy code
Installation
Copy code
Brings alonglocale
Usage
ImportCopy code
API reference
RelativeTime
| Prop | Type | Default |
|---|---|---|
valuerequired | Instant | – |
now | Instant | – |
locale | string | – |
timeZone | string | – |
intervalMs | number | – |
formatStyle"short" ("2 min. ago") or "narrow" where space is tight; "long" by default. | Intl.RelativeTimeFormatStyle | – |
Also takes <time> attributes and render except children, dateTime.
Other exports
formatElapsedformatInstantformatRelativetoISOtoTimeuseNowtype FormatInstantOptionstype FormatRelativeOptionstype Instanttype RelativeTimePropstype UseNowOptionsAccessibility
- A <time> element whose title holds the exact instant in the reader's time zone.
Agent actions
Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.