Formatters
Relative Time
Renders a localised, auto-updating relative timestamp — "2 hours ago", "in 3 days" — from a date. It refreshes itself on a cadence proportional to the elapsed time (every second under a minute, every minute under an hour, and so on) and outputs a semantic <time> element carrying the machine readable datetime plus an absolute title for accessibility.
Preview
Section titled “Preview”<nana-relative-time date="2026-01-01T00:00:00Z"></nana-relative-time> - Paid
- Reading taken
- Lease ends
<script lang="ts">
import { NanaRelativeTime } from '$lib/components/ui/relative-time';
const now = Date.now();
</script>
<ul class="flex flex-col gap-1 text-sm">
<li>Paid <NanaRelativeTime date={now - 45_000} /></li>
<li>Reading taken <NanaRelativeTime date={now - 3 * 3_600_000} /></li>
<li>Lease ends <NanaRelativeTime date={now + 40 * 86_400_000} format="short" /></li>
</ul> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add relative-time --framework web-componentsnpx @nana-tec/ui add relative-time --framework svelteLands in src/lib/components/ui/relative-time/ as NanaRelativeTime.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/relative-time";
Copied in with npx @nana-tec/ui add relative-time? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<script lang="ts"> import { NanaRelativeTime } from '$lib/components/ui/relative-time';</script>
<NanaRelativeTime date="2026-03-10T09:30:00Z" />Renders a <time> with the exact moment in datetime and the full date in its title. It
refreshes as time passes, more often for recent moments; set live={false} to fix it.
Basic usage
Section titled “Basic usage”<nana-relative-time date="2026-01-01T00:00:00Z"></nana-relative-time>Styles
Section titled “Styles”<nana-relative-time date="2026-06-15T08:00:00Z"></nana-relative-time>
<nana-relative-time
date="2026-06-15T08:00:00Z"
format="short"
></nana-relative-time> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
date | date | Date | string | number | new Date() | The date — a Date, an ISO string, or a timestamp |
format | format | RelativeTimeStyle | 'long' | Wording length passed to Intl.RelativeTimeFormat |
live | live | boolean | true | Keep the value refreshing as time passes |
locale | locale | string | undefined | — | BCP 47 locale (defaults to the document locale) |
CSS parts
| Part | Description |
|---|---|
::part(time) | The time element |
NanaRelativeTime
| Prop | Type | Default |
|---|---|---|
daterequired | Date | string | number | |
format | RelativeTimeStyle | 'long' |
locale | string | |
live | boolean | true |
Also accepts HTMLAttributes<HTMLTimeElement>.