var date = new Date();
// 获取月份(注意月份从0开始计数)
var month = date.getMonth() + 1; // 需要加上1才能得到正确的月份值
// 根据不同的月份设置相应的节日信息
if (month === 1 && date.getDate() === 1) {
console.log("今天是元旦");
} else if (month === 2 && date.getDate() === 14) {
console.log("今天是情人节");
} else if (month === 3 && date.getDate() === 8) {
console.log("今天是妇女节");
} else if (month === 4 && date.getDate() === 4) {
console.log("今天是清明节");
} else if (month === 5 && date.getDate() === 1) {
console.log("今天是劳动节");
} else if (month === 5 && date.getDay() === 0) {
console.log("今天是母亲节");
} else if (month === 6 && date.getDay() === 0) {
console.log("今天是父亲节");
} else if (month === 6 && date.getDate() >= 24 && date.getDate() <= 27) {
console.log("今天是端午节");
} else if (month === 9 && date.getDate() === 10) {
console.log("今天是教师节");
} else if (month === 10 && date.getDate() === 1) {
console.log("今天是国庆节");
} else if (month === 12 && date.getDate() === 25) {
console.log("今天是圣诞节");
} else {
console.log("今天没有特定的节日");
}
js 实现判断节假日
最新推荐文章于 2024-04-03 19:06:58 发布