postdischarge-ui/src/utils/obtainendtime.js
2024-04-16 15:37:25 +08:00

35 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//获取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 }