javascript代码小抄人生如逆旅,我亦是行人。
最后更新于2025-03-12 17:54:26
最后更新于2025-03-12 17:54:26
获取工作日
function getWorkdays() {
const startDate = new Date(document.querySelector("[name='startime']").value);
const endDate = new Date(document.querySelector("[name='endtime']").value);
const holidays = {{ holidays|safe if holidays else [] }}; //节假日
const extradays = {{ extradays|safe if extradays else [] }}; //补班
let days = 0;
let currentDate = startDate;
// 确保结束日期在开始日期之后
if (currentDate > endDate) {
[startDate, endDate] = [endDate, startDate];
}
while (currentDate <= endDate) {
const temp = currentDate.getFullYear().toString() + '-' + (currentDate.getMonth() + 1).toString() + '-' + currentDate.getDate().toString();
if (![0, 6].includes(currentDate.getDay()) && !holidays.includes(temp) || extradays.includes(temp)) {
days++;
}
currentDate.setDate(currentDate.getDate() + 1);
}
document.querySelector("[name='spentime']").value = days;
}
- 本文作者:畄月寒
- 本文链接:https://testpoo.github.io/javascript代码小抄.html
- 版权声明:本铺所有文章除特别声明外,均采用 BY-NC-SA 4.0 许可协议。转载请注明出处!