获取当前时间日期及之后7天和星期几

https://blog.csdn.net/liyongchunscr/article/details/122993293

	//获取当前年月日
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1; //得到月份
	var date = now.getDate(); //得到日期
	//data = year + "年" + month + "月" + date + "日" ;

	//从当前时间往后7天
	var check = [];
	for (let i = 0; i < 7; i++) {
		//24 * 3600 * 1000 就是计算一天的时间 
		var date = new Date(now.getTime() + i * 24 * 3600 * 1000);
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var day = date.getDate();
		var dt2 = new Date(now.getTime() + i * 24 * 3600 * 1000);
		var weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
		var weekDays = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];

		//把七天的时间和星期添加到数组中
		check.push({
			date: year + "-" + month + "-" + day,
			day: day,
			weekday: weekDays[dt2.getDay()],
			week: weekDay[dt2.getDay()],
		});
	}
	// console.log(check);

你可能感兴趣的:(#,JS,javascript,vue.js,开发语言)