教程 date-fns tutorial

getMonth

返回给定日期的月份(从 0 到 11)。

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

// 示例日期
const date = new Date(2024, 4, 15); // 2024年5月15日

// 获取给定日期的月份
const month = getMonth(date);

console.log("给定日期的月份:", month);
// 给定日期的月份:4