前端yyyy-mm-dd格式 计算一段工作日后,日期


//计算一段工作日后,日期
getWorkday(dat, itervalByDay) {
function formatTen(f) {
if (parseInt(f, 10) < 10) {
return '0' + f;
}
return f;
}

let str = dat.split("-");
let date = new Date();
date.setUTCFullYear(str[0], str[1] - 1, str[2]);
date.setUTCHours(0, 0, 0, 0);
let millisceonds = date.getTime();
for (let i = 1; i <= itervalByDay; i++) {
millisceonds += 24 * 60 * 60 * 1000;
date.setTime(millisceonds);
}
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
return year + "-" + formatTen(month) + "-" + formatTen(day);
},
 
posted on 2021-10-08 17:29  云淡风轻博客  阅读(219)  评论(0编辑  收藏  举报