uniapp获取7天日期和周几

uniapp获取7天日期和周几

// 获取7天
			getWeekqq(dateString) {
				var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];  
			var myDate = new Date(Date.parse(dateString));  
			return weekDay[myDate.getDay()]
			},
			getTime() {
				var date = new Date();
				var base = Date.parse(date); // 转换为时间戳
				var year = date.getFullYear(); //获取当前年份
				var mon = date.getMonth() + 1; //获取当前月份
				var day = date.getDate(); //获取当前日
				var oneDay = 24 * 3600 * 1000
				var daytime = `${year}-${mon >= 10 ? mon : '0' + mon}-${day >= 10 ? day : '0' + day}`; //今日时间
				var daytimeArr = [
					{
						data: daytime,
						week: this.getWeekqq(daytime),
						day: `${mon}/${day}`
					}
				]
				for (var i = 1; i < 7; i++) { //今天以及后6天
					var now = new Date(base += oneDay);
					var myear = now.getFullYear();
					var month = now.getMonth() + 1;
					var mday = now.getDate()
					daytimeArr.push({
						data: [myear, month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('-'),
						week: this.getWeekqq([myear, month >= 10 ? month : '0' + month, mday >= 10 ? mday : '0' + mday].join('-')),
						day: [month, mday].join('/')
					})
				}
				return daytimeArr
			},

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