You can use the date-fns library to do that.
import { formatDistanceToNow } from "date-fns";
const timeDistance = (time) => formatDistanceToNow(time, { addSuffix: true });
timeDistance(new Date()); // 1 second ago (results may vary)
You can use the date-fns library to do that.
import { formatDistanceToNow } from "date-fns";
const timeDistance = (time) => formatDistanceToNow(time, { addSuffix: true });
timeDistance(new Date()); // 1 second ago (results may vary)