Skip to main content
Version: 5.0.3



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


npm install --save rooks

Importing the hook#

import { useTimeAgo } from 'rooks';


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 (
render(<Demo />);


ArgumentTypeDescriptionDefault value
inputDateTimestampetcAny input that time-ago.js supportsundefined
optionsObjectOptions object{ intervalMs:0 }


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