Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 892 Bytes

is-weekend.md

File metadata and controls

32 lines (20 loc) · 892 Bytes
标题 标签
isWeekend(是否是周末) type(类型)

检查给定日期是否为周末。

  • 使用 Date.prototype.getDay() 通过取模运算符 (%) 检查周末。
  • 省略参数 d 以使用当前日期作为默认值。
const isWeekend = (d = new Date()) => d.getDay() % 6 === 0;

ts代码如下:

调用方式:

isWeekend(); // true (if current date is 2022-11-05)

应用场景

以下是一个实战示例:

结果如下:

<iframe src="codes/javascript/html/isWeekend.html"></iframe>