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
| Type | Required | Default | Description |
|---|---|---|---|
| string | No | none | Use alternate display format. Possible values: short, narrow. |
<FormattedRelativeTime
value={-30}
unit="minute"
form="short"
/>
// 30 min. ago
unit
| Type | Required | Default | Description |
|---|---|---|---|
| string | Yes | none | Unit 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
| Type | Required | Default | Description |
|---|---|---|---|
| Date or number | Yes | none | Date or number to be formatted. |