当前位置:网站首页>添加给定的工作日数后计算日期
添加给定的工作日数后计算日期
2022-07-20 04:08:00 【紫微前端】
- 用于构造一个等于要添加的工作日
Array.from()
的数组。lengthcount
- 用于
Array.prototype.reduce()
遍历数组,从开始startDate
并递增,使用Date.prototype.getDate()
andDate.prototype.setDate()
。 - 如果当前
date
是周末,则通过添加一天或两天使其成为工作日再次更新。 - 注意:不考虑法定节假日。
const addWeekDays = (startDate, count) =>
Array.from({ length: count }).reduce(date => {
date = new Date(date.setDate(date.getDate() + 1));
if (date.getDay() % 6 === 0)
date = new Date(date.setDate(date.getDate() + (date.getDay() / 6 + 1)));
return date;
}, startDate);
addWeekDays(new Date('Oct 09, 2020'), 5); // 'Oct 16, 2020'
addWeekDays(new Date('Oct 12, 2020'), 5); // 'Oct 19, 2020'
边栏推荐
猜你喜欢
BOM browser object model (Part 1) - overview, common events of window object, JS execution mechanism (close advertisement after 5 seconds, countdown case, send SMS countdown case)
All operations after deleting a field in Excel
Hands on experiment of network and VPC
Exness: the dollar fell moderately, and the RBA called for further interest rate hikes
请别再使用 SimpleDateFormat 格式化时间了,DateTimeFormatter 更出色!
Pyhon crawls Beijing's 10-year weather data
The difference between break, continue and return
金蝶上半年“答卷”预告:大客户战略持续突破,ARR同比增长45%以上
kettle
Shengteng AI innovation competition | Shengsi track live training, the guide for obtaining up to 10million bonuses is coming
随机推荐
Application of "tutorial" torchtext
Method of creating thread
Leetcode sword finger offer 11 Rotate the minimum number of the array
Leetcode sword finger offer 32 - I. print binary tree from top to bottom
进程和线程
Redis distributed lock + thread pool
首选线程池,而不是多线程
机器学习之集成学习(Ensemble Learning)
exness:美元温和回落,澳洲联储呼吁进一步加息
Regular expression tutorial notes
Pytorch:model.train()和model.eval()用法和区别,以及model.eval()和torch.no_grad()的区别
Several common models of convolutional neural network CNN
All operations after deleting a field in Excel
* 反射获取常用的三种方式: * Class c = Class.forName(“完整类名带包名“); * Class c = Object.getClass(); /
目标检测的类别损失和位置损失
Records from July 18, 2022 to July 25, 2022
加锁熟悉synchronized和Lock,那么它们有什么区别
Caffeine cache add change check expired
typora测试版过期无法正常使用
SQL Server 2008 R2 uninstall failed