postdischarge-ui/src/utils/obtainendtime.js

35 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-03-20 11:31:50 +08:00
//获取endtime
function obtainendtime(starttime, item) {
let currentDate = new Date(starttime)
let nextDate
if (item.packageTermUnit == '年') {
currentDate.setFullYear(currentDate.getFullYear() + Number(item.packageTerm));
currentDate.setDate(currentDate.getDate() - 1);
let nextYear = currentDate.getFullYear();
let nextMonth = checkMonth(currentDate.getMonth() + 1);// 因日期中的月份表示为0-11所以要显示正确的月份需要 + 1
let nextday = checkMonth(currentDate.getDate())
nextDate = nextYear + "-" + nextMonth + "-" + nextday; // "2019-05"
} else if (item.packageTermUnit == '月') {
currentDate.setMonth(currentDate.getMonth() + Number(item.packageTerm)); // 加一个月
currentDate.setDate(currentDate.getDate() - 1); // 减一天
let nextYear = currentDate.getFullYear();
let nextMonth = checkMonth(currentDate.getMonth() + 1);// 因日期中的月份表示为0-11所以要显示正确的月份需要 + 1
let nextday = checkMonth(currentDate.getDate())
nextDate = nextYear + "-" + nextMonth + "-" + nextday; // "2019-05"
} else if (item.packageTermUnit == '日') {
currentDate = new Date(currentDate.setDate(currentDate.getDate() + Number(item.packageTerm)));
let nextYear = currentDate.getFullYear();
let nextMonth = checkMonth(currentDate.getMonth() + 1);// 因日期中的月份表示为0-11所以要显示正确的月份需要 + 1
let nextday = checkMonth(currentDate.getDate())
nextDate = nextYear + "-" + nextMonth + "-" + nextday; // "2019-05"
}
return nextDate
}
function checkMonth(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
export { obtainendtime }