Version: Next

use-time-ago

About#

A React Hook to get time ago for timestamp millisecond value.


Installation#

npm install --save @rooks/use-time-ago

Importing the hook#

import useTimeAgo from "@rooks/use-time-ago"

Usage#

function Demo() {
const [date, setDate] = useState(new Date());
const timeAgo = useTimeAgo(date.getTime() - 1000 * 12, {
locale: "zh_CN"
});
const timeAgo2 = useTimeAgo(date.getTime() - 1000 * 12);
return (
<>
<p>{timeAgo}</p>
<p>{timeAgo2}</p>
</>
);
}
render(<Demo/>)

Arguments#

ArgumentTypeDescriptionDefault value
inputDateTimestampetc
optionsObjectOptions object{ intervalMs:0 }

Options#

OptionsTypeDescriptionDefault value
intervalMsmillisecondsDuration after which time-ago has to be calculated1000
localeStringLocale in which value is expectedundefined
relativeDateDateRelative date object with respect to which time-ago is to be calcuatedCurrent Time

Returned Value#

Timeago string is returned.

Join Bhargav's discord server#

You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.

Last updated on by imbhargav5