教程 date-fns tutorial

constructFrom

从指定日期部分构建一个新的日期对象。

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

// 示例日期部分
const dateParts = {
  year: 2024,
  month: 4,
  day: 15,
  hours: 12,
  minutes: 30,
  seconds: 45,
  milliseconds: 500,
};

// 从指定日期部分构建一个新的日期对象
const constructedDate = constructFrom(dateParts);

console.log("从指定日期部分构建的日期对象:", constructedDate);
// 从指定日期部分构建的日期对象:Sun May 12 2024 12:30:45 GMT+0800