根据输入日期, 获取7天内的星期几和日期,并判断是否是当天
data(){ rerurn{ daterange:[0,7] } }, methods:{
initShowMeetDay(day){
this.thisWeekDay = this.getWeekDays(day)
console.log(this.thisWeekDay)
},
getWeekDays(input_day) {
var nowdate = this.formateDate(new Date());
var weekDayArr = ["日", "一", "二", "三", "四", "五", "六"];
var thisWeekDay = [];
for (var i = this.daterange[0]; i < this.daterange[1]; i++) {
let tmpobj = []
let tempThisDate = "";
let tmpdate = new Date(input_day)
tmpdate.setDate(tmpdate.getDate() + i);
tempThisDate = this.formateDate(tmpdate)
tmpobj.push(weekDayArr[tmpdate.getDay()])
tmpobj.push(tmpdate.getDate())
tmpobj.push(tmpdate)
tmpobj.push(nowdate == tempThisDate) //是否是当天(今天)
thisWeekDay.push(tmpobj)
}
return thisWeekDay;
},
formateDate(date){
var d = new Date(date);
var year = d.getFullYear();
var month = d.getMonth()+1;
var day = d.getDate();
var newDate = year+"-"+month+"-"+day;
return newDate;
},
}
结果如下: