35 lines
1.8 KiB
JavaScript
35 lines
1.8 KiB
JavaScript
|
|
//获取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 }
|