intl-timeago
v1.0.2
Published
A relative time formatter based on Intl.RelativeTimeFormat for JS and React
Downloads
9
Maintainers
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 objectoptions.locale
- Locale string, optional, default is inferred from the browseroptions.live
- Boolean or Number, default istrue
, iftrue
the timeago will update every second, iffalse
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