Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-timeago-i18n

k-yle1.2kMIT2.4.0TypeScript support: included

📅🌏 A relative time component for react using the browser's native internationalization API

react, timeago, relative date, date, i18n, intl, internationalization

readme

react-timeago-i18n

build npm version npm bundle size

📅🌏 A tiny relative time component for react, which uses the browser's native Intl.RelativeTimeFormat API. This means that all languages are supported without bundling translations.

This library is 0.8 kB, which is significantly smaller than react-timeago which is 96 kB.

Install

npm install react-timeago-i18n

Usage

import TimeAgo from "react-timeago-i18n";

<TimeAgo date="2019-07-16" /> // --> "4 years ago"
<TimeAgo date="2019-07-16" locale="de-AT" /> // --> "vor 4 Jahren"

Props

Property Description Default Value
date string or Date -
locale the language to use navigator.language
formatOptions options for Intl.RelativeTimeFormat undefined
allowFuture By default, only dates in the past are supported. If you want to display future dates (i.e. "in 3 days") set this property to true false
hideSeconds By default, values smaller than 1 minute will shown as "1 minute" instead of frequently updating seconds, unless you set this property to false. true
hideSecondsText When using hideSeconds, seconds are displayed as "1 minute ago" or "in 1 minute", use this property to provide custom strings i.e. ["just now", "right now"] []
roundStrategy By default, values are rounded (e.g. 11.9 months becomes "2 years"). If this is not desired, the rounding strategy can be changed to floor. "round"
timeElement By default, the result is wrapped in <time title="..."> ... </time>, unless you set this property to false true

Context Provider

Options can be specified as props, or using a context provider.

For example:

import TimeAgo, { TimeAgoProvider } from "react-timeago-i18n";

<TimeAgoProvider locale="zh-Hans" hideSeconds>
  ...
  <TimeAgo date="2019-07-16" />
  ...
</TimeAgoProvider>;

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

2.4.0 (2025-03-09)

  • Support passing number to the date option.
  • Support passing string[] to the locale option.

2.3.0 (2024-11-22)

  • Use a TypeScript namespace for all type defintions
  • Performance improvements

2.2.1 (2024-06-19)

  • Republish to npm due to EINTEGRITY error

2.2.0 (2024-06-16)

  • Added a new option: allowFuture, to support dates in the future.
  • Added a new option: hideSecondsText, for providing a custom message when hideSeconds=true
  • Added react v19 to peerDependencies

2.1.1 (2024-02-26)

2.1.0 (2024-02-23)

  • Support old versions of react (pre v16.14)
  • Prefer idiomatic phrasing by default (use numeric: 'always' for the old behaviour)
  • Added a context provider to allow default options to be specified

2.0.0 (2024-02-09)

  • 💥 BREAKING CHANGE: Enable hideSeconds by default
  • 💥 BREAKING CHANGE: Set roundStrategy to round by default
  • 💥 BREAKING CHANGE: Wrap output in <time>...</time> by default.
  • Add timeElement option to determine whether a <time> element should be used.

1.1.0 (2023-07-07)

  • Add roundStrategy option

1.0.1 (2023-05-23)

  • Fix bug in hideSeconds mode

1.0.0 (2023-05-18)

  • Initial release