欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js获取后七天的数据,如通过获取一周的周一的时间,然后计算出周日的日期

程序员文章站 2024-03-07 13:08:39
...
getSevenDay(date){
	//
	let today = new Date(date);
	let seven_milliseconds = today.getTime()+1000*60*60*24*6;
	let sevenDay = new Date();
	sevenDay.setTime(seven_milliseconds);

	let strYear=sevenDay.getFullYear();
	let strDay=sevenDay.getDate();
	let strMonth=sevenDay.getMonth()+1;
	if(strMonth<10)
	{
		strMonth="0"+strMonth;
	}
	if (strDay<10){

		strDay = "0"+strDay;
	}
	let strSevenDay=strYear+"-"+strMonth+"-"+strDay;
	return strSevenDay
}

相关标签: javascript es6