Version: v3.6.0

@rooks/use-time-ago#

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


Build Status

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.

Last updated on by imbhargav5