// 获取当前一周的时间
getWeekTime() {
let that = this;
this.userForm.TimeChoose = [];
var currentFirstDate;
var formatDate = function(date) {
var year = date.getFullYear() + "-";
var month = date.getMonth() + 1 + "-";
var day = date.getDate() + "";
return year + month + day;
};
var addDate = function(date, n) {
date.setDate(date.getDate() + n);
return date;
};
var setDate = function(date) {
var week = date.getDay() - 1;
date = addDate(date, week * -1);
currentFirstDate = new Date(date);
var arr = [];
for (var i = 0; i < 7; i++) {
var a = formatDate(i == 0 ? date : addDate(date, 1)); //星期一开始
arr.push(a);
}
return arr;
};
setDate(new Date());
var num = 0; //num为0时表示当前周,递增或递减时周数也递增或递减
let setWeek = setDate(addDate(currentFirstDate, 7 * num));
this.userForm.TimeChoose = setWeek;
},
js获取当前一周的时间
最新推荐文章于 2024-08-02 16:50:48 发布