formatRelative

返回相对于当前时间的日期描述字符串。

import { formatRelative } from "date-fns";

// 示例日期
const date = new Date(2024, 0, 1); // 2024年1月1日

// 格式化相对日期
const relativeDateString = formatRelative(date, new Date());

console.log(`相对日期描述字符串:${relativeDateString}`); // 相对日期描述字符串:in 2 years