intl-timeago

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i intl-timeago

Weekly Downloads

9

Version

1.0.2

License

ISC

Unpacked Size

6.5 kB

Total Files

12

Last publish

Collaborators

  • alexmeah