fn
formatTimeAgo
v0.0.15testeddemoPure (non-reactive) relative-time formatter. Useful on its own and reused by `useTimeAgo` on every tick.
Example
ts
formatTimeAgo(new Date(Date.now() - 3 * 60_000)); // '3 minutes ago'Demo
Loading demo…
Signature
ts
export function formatTimeAgo<UnitNames extends string = UseTimeAgoUnitName>(
from: Date,
options: FormatTimeAgoOptions<UnitNames> ={ ... }Type Parameters
UnitNamesextends string= UseTimeAgoUnitNameParameters
| Parameter | Type | Description |
|---|---|---|
from | Date | The instant to describe |
options? | FormatTimeAgoOptions<UnitNames> | Formatting options |
now? | number | Date | The reference "now" |
Returns
stringThe localized relative-time string