FormattedRelativeTime

February 21, 2020 ยท View on GitHub

Formats a relative time based on the locale and options.

Usage

import { FormattedRelativeTime } from 'react-native-globalize';

const ExampleComponent = () => (
  <FormattedRelativeTime
    unit="auto"
    value={new Date()}
  />
);
// now

const ExampleComponent2 = () => (
  <FormattedRelativeTime
    unit="minute"
    value={-30}
  />
);
// 30 minutes ago

Props

form

TypeRequiredDefaultDescription
stringNononeUse alternate display format. Possible values: short, narrow.
<FormattedRelativeTime
  value={-30}
  unit="minute"
  form="short"
/>
// 30 min. ago

unit

TypeRequiredDefaultDescription
stringYesnoneUnit of time to use (see note below).

When value is a number, unit can be: second, minute, hour, day, week, month, quarter, year. When value is a Date, auto is also supported, which will determine the best unit automatically.

value

TypeRequiredDefaultDescription
Date or numberYesnoneDate or number to be formatted.