Relative time

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

  • @primer/react@36.27.0
  • Alpha
  • Not reviewed for accessibility

Import

import {RelativeTime} from '@primer/react'

Examples

View in Storybook

Props

RelativeTime

NameDefaultDescription
datetimeRequired
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''auto' | 'micro' | 'elapsed'

The format with which to display the time

tense
'auto''auto' | 'past' | 'future'

The tense to use when displaying a relative time

precision
'second''year' | 'month' | 'day' | 'hour' | 'minute' | 'second'

The precision to use when displaying an elapsed time

threshold
'P30D'string

The threshold (ISO8601 duration) to display relative dates within

prefix
'on'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''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

as
"relative-time"React.ElementType
sx
SystemStyleObject
Navigated to Relative time