//本周、下一周日期
var date=new Date();
var currentFirstDate=new Date(date);
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 weekList=[];
for(var i = 0;i<7;i++){
weekList[i]=formatDate(i==0 ? date : addDate(date,1));
}
return weekList
};
var thisWeek=setDate(addDate(currentFirstDate,0));//本周
var nextWeek=setDate(addDate(currentFirstDate,7));//下周
var today=formatDate(date);//今日日期
console.log(thisWeek);
console.log(nextWeek);
js 获取本周、上一周、下一周日期
最新推荐文章于 2024-08-02 16:50:48 发布