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

Package detail

intl-timeago

alexmeah6ISC1.0.2TypeScript support: included

A relative time formatter based on Intl.RelativeTimeFormat for JS and React

intl, timeago, relative time, react, RelativeTimeFormat, Intl.RelativeTimeFormat

readme

intl-timeago

Installation

npm install intl-timeago

Usage

Function

import { timeAgo } from "intl-timeago";

const date = new Date();
const timeAgo = timeAgo(date, "en-US");
console.log(timeAgo); // now

React

Options

  • date - Date object
  • options.locale - Locale string, optional, default is inferred from the browser
  • options.live - Boolean or Number, default is true, if true the timeago will update every second, if false the timeago will not update, if a number the timeago will update every number of milliseconds
import { useTimeAgo } from "intl-timeago/useTimeAgo";

const date = new Date();

const TimeAgo = () => {
  const timeAgo = useTimeAgo(date);
  return <span>{timeAgo}</span>;
};

export default TimeAgo;

Formatting

  • now
  • x seconds ago
  • x minutes ago
  • x hours ago
  • today/yesterday
  • x days ago
  • this week/last week
  • x weeks ago
  • this month/last month
  • x months ago
  • this year/last year
  • x years ago

License

MIT