Skip to content

FormatRelativeTime

Used to format relative times.

Just now
In 15d
Happened 5h ago
import { FormatRelativeTime } from '@fintech-sandpit/ui/react';
return (
<FormatRelativeTime
date={new Date()}
/>
<FormatRelativeTime
date={new Date(Date.now() + 1000 * 60 * 60 * 24 * 15)}
/>
<FormatRelativeTime
date={new Date()}
now={new Date(Date.now() + 1000 * 60 * 60 * 5)}
options={{
hourAgo: 'Happened %h ago',
}}
/>
);
NameTypeRequiredDefaultDescription
dateDate | stringYesDate to format
nowDate | stringDate.now()Date to use for comparison
optionsobject—Options to use for formatting
OptionDefaultExampleDescription
justNow'Just now'Just nowText to display if the date is just now
inMin'In %m'In 15mText to display the future date in minutes
minAgo'%m ago'15m agoText to display the past date in minutes
inHour'In %h'In 1hText to display the future date in hours
hourAgo'%h ago'1h agoText to display the past date in hours
inDay'In %d'In 1dText to display the future date in days
dayAgo'%d ago'1d agoText to display the past date in days
inMonth'In %mo'In 1moText to display if the date is in months
monthAgo'%mo ago'1mo agoText to display the past date in months
inYear'In %y'In 1yText to display the future date in years
yearAgo'%y ago'1y agoText to display the past date in years
notSoon'Not anytime soon'Not anytime soonText to display if the date is not soon
longAgo'Long time ago'Long time agoText to display if the date is long ago