Data Display

RelativeTime

Live-updating relative or absolute time label in the viewer's zone, with the other reading in a tooltip.

import { RelativeTime } from '@lostgradient/cinder';
relative-time
01

Overview

Reference usage

RelativeTime renders a localized relative timestamp and can keep it current as time passes.

Usage

svelte
<script lang="ts">
  import { RelativeTime } from '@lostgradient/cinder';
</script>

<RelativeTime date="2026-08-28T18:00:00Z" />

It reads in the viewer's time zone on one 12-hour clock: "just now", "4 min ago", "1 h ago", then "Yesterday, 4:12 PM" and "Sun Nov 1, 4:12 PM". Set format="absolute" for a label that is never relative ("Today, 10:44 AM"); the tooltip then carries the relative reading, and the relative label's tooltip carries the full dated reading. The same formats are exported as functions: formatRelativeTime, formatDateTime, formatDayHeading ("Today, Central time"), formatTimeZoneLabel ("CST" or "Central time") and formatScheduleTime ("3:00 AM (9:00 AM UTC)").

Live preview

Absolute time with a relative tooltip

02

When to use

Use when
  • Showing when a message, issue, or event happened.
Avoid when
  • An exact calendar date is required.
03

Examples

Absolute time with a relative tooltip

format="absolute" always reads the clock ("Today, 10:44 AM", "Sun Nov 1, 4:12 PM"), never relative: it says Today and names every other day, and the relative reading moves into the tooltip. Pass dayWords={true} to say Yesterday too. Use it for an "Updated" column that has to name the moment.

RelativeTime

Displays a localized label for a timestamp relative to the current time.

Central time on one 12-hour clock

The date utilities behind RelativeTime read in the viewer’s zone on one 12-hour clock. This example pins the zone to Central time and "now" to Mon Nov 2, 10:46 AM so the readings are the same every time.

04

Props

Props for relative-time
Name
Type
Default
Description
date text The moment to show: a Date, an ISO string or epoch milliseconds. Defaults to now.
locale text Locale for the label. Defaults to the surrounding locale context, then the browser's language.
timeZone text IANA time zone the label is read in. Defaults to the viewer's zone.
format 'relative' | 'absolute' 'relative' relative reads "4 min ago", "1 h ago", then "Yesterday, 4:12 PM". absolute always reads the clock ("Today, 10:44 AM", "Sun Nov 1, 4:12 PM"). The tooltip carries the other reading.
dayWords boolean Which days the label may name with a word. true says "Today", "Yesterday" and "Tomorrow"; 'today' says only "Today" and names every other day ("Sun Nov 1, 4:12 PM"); false always names the calendar day. Defaults to 'today' for format="absolute" and true for relative.
seconds boolean false Counts the first minute in seconds ("4 s ago", and "just now" before the third second), for a time that is a heartbeat or a pulse, such as a worker last heard from. The label then ticks every second during that minute. Applies to the relative format.
tick boolean true Recalculate the label on an interval. Set false to disable ticking.
children snippet