npm install intl-timeago
import { timeAgo } from "intl-timeago";
const date = new Date();
const timeAgo = timeAgo(date, "en-US");
console.log(timeAgo); // now
-
date
- Date object -
options.locale
- Locale string, optional, default is inferred from the browser -
options.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;
- 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
MIT