RelativeTime

RelativeTime displays time in a way that is clear, concise, and accessible.

Page navigation navigation

React
readyNot reviewed for a11y
Rails
readyNot reviewed for a11y

This component's features all come from the relative-time-element (GitHub staff only) custom element.

React examples

Default

Jan 2, 2020

With time

Jan 2, 2020

With leading zeros

Number formatting guidelines

Jan 2, 2020

Without "on" prefix

Word formatting guidelines

Jan 2, 2020

Micro format

Jan 2, 2020

Without a title attribute

Jan 2, 2020
Jan 2, 2020

Props

RelativeTime

NameRequiredDescription
datetime
Required
string
An ISO8601 time representing the time
date
string
Instead of passing the `datetime`, it is possible to pass a full `Date` object into the `date` prop
format
'auto' | 'micro' | 'elapsed'
The format with which to display the time
tense
'auto' | 'past' | 'future'
The tense to use when displaying a relative time
precision
'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'
The precision to use when displaying an elapsed time
threshold
string
The threshold (ISO8601 duration) to display relative dates within
prefix
string
The prefix to use when displaying a localised (non relative) date
second
'numeric' | '2-digit'
The format with which to render seconds
minute
'numeric' | '2-digit'
The format with which to render minutes
hour
'numeric' | '2-digit'
The format with which to render hours
weekday
'short' | 'long' | 'narrow'
The format with which to render weekdays
day
'numeric' | '2-digit'
The format with which to render days
month
'numeric' | '2-digit' | 'short' | 'long' | 'narrow'
The format with which to render months
year
'numeric' | '2-digit'
The format with which to render years
timeZoneName
'long' | 'short' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric'
The format with which to render the time zone
ref
React.RefObject<RelativeTimeElement>
noTitle
boolean
Removes the `title` attribute provided on the element by default
attributeChangedCallback
(attrName: string, oldValue: unknown, newValue: unknown) => void
connectedCallback
() => void
onRelativeTimeUpdated
null | (event: RelativeTimeUpdatedEvent) => void
update
() => void
as
React.ElementType
sx
SystemStyleObject