教程 date-fns tutorial

getTime

返回给定日期的时间戳,表示自 1970 年 1 月 1 日 00:00:00 UTC 以来的毫秒数。

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

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

// 获取日期的时间戳
const timestamp = getTime(date);

console.log("时间戳:", timestamp);
// 时间戳:1704067200000