教程 date-fns tutorial

roundToNearestMinutes

将给定日期舍入到最接近的分钟。

javascript
import { roundToNearestMinutes } from "date-fns";

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

// 将日期舍入到最接近的 10 分钟
const roundedDate = roundToNearestMinutes(date, { nearestTo: 10 });

console.log("舍入后的日期:", roundedDate);
// 舍入后的日期:Sun Jan 01 2024 12:30:00