Day.js 本身并不支持节假日的判断,不过可以通过三方插件或类库实现,下面列举两个示例:
# chinese-workday
# 安装
https://www.npmjs.com/package/chinese-workday (opens new window)
npm install chinese-workday
# 使用
// const { isWorkday, isHoliday, getFestival } = require('chinese-workday');
const ww = require('chinese-workday');
const isWorkday = ww.isWorkday;
const isHoliday = ww.isHoliday;
const getFestival = ww.getFestival;
const isAddtionalWorkday = ww.isAddtionalWorkday;
isWorkday('2022-10-01')
// => false
isHoliday('2022-10-01')
// => true
isAddtionalWorkday('2022-01-29')
// => true
getFestival('2022-10-01')
// => 国庆节
# chinese-calendar
# 安装
https://www.npmjs.com/package/chinese-calendar (opens new window)
npm i chinese-calendar
yarn add chinese-calendar
# 使用
浏览器下(基于 webpack 构建)
import calendar from 'chinese-calendar'
calendar.isHoliday('2020-10-08') // true
calendar.getHolidayDetail('2020-10-07') // ['National Day', '国庆节', 3]
NodeJS 下
const calendar = require('chinese-calendar')
calendar.isHoliday('2020-10-08') // true
calendar.getHolidayDetail('2020-10-07') // ['National Day', '国庆节', 3]
# 更多
← 时区