vue 根据当前日期获取其前七天的日期

查询最近七天数据:日期显示
在这里插入图片描述

vue调用

this.month = getRecentDay()

js:


/**
 * 根据当前日期获取其前七天的日期
 * @param month
 * @return {Array|*}
 */
export function getRecentDay() {
	let arr = []
	for(let i = 6;i >= 0;i --) {
		let temp = getDay(-i)
		arr.push(temp)
	}
	return arr;
}

function getDay(day){
    var today = new Date();
    var targetday_milliseconds = today.getTime() + 1000*60*60*24*day;
    today.setTime(targetday_milliseconds); 
    var tMonth = today.getMonth();
    var tDate = today.getDate();
    tMonth = doHandleMonth(tMonth + 1);
    tDate = doHandleMonth(tDate);
    return tMonth + "-" + tDate;
}
function doHandleMonth(month){
    var m = month;
    if(month.toString().length == 1){
     m = "0" + month;
    }
    return m;
}

猜你喜欢

转载自blog.csdn.net/ka_xingl/article/details/118902805
今日推荐