Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 955 Bytes

max-date.md

File metadata and controls

38 lines (26 loc) · 955 Bytes
标题 标签
maxDate(查找最大日期) date(日期)

返回给定日期的最大值。

  • 使用带有 Math.max() 的 ES6 传播语法来查找最大日期值。
  • 使用 Date 构造函数将其转换为 Date 对象。
const maxDate = (...dates) => new Date(Math.max(...dates));

ts 代码如下:

调用方式:

const dates = [
  new Date(2017, 4, 13),
  new Date(2018, 2, 12),
  new Date(2016, 0, 10),
  new Date(2016, 0, 9)
];
maxDate(...dates); // 2018-03-11T22:00:00.000Z

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/max-date.html"></iframe>