获取最近七天的日期和星期几

const now = new Date();
     const nowTime = now.getTime() ;
     const oneDayTime = 24*60*60*1000 ;
const arry = [-3,-2,-1,0,1,2,3];
const weekDate=[]
     for(let item of arry){
         const ShowTime = nowTime + item*oneDayTime ;
         //初始化日期时间
         const myDate = new Date(ShowTime);
         const year=myDate.getFullYear();
         const month=myDate.getMonth()+1;
const date=myDate.getDate();
const week="日一二三四五六".charAt(myDate.getDay())
weekDate.push( {year,month,date,week} )
     }

猜你喜欢

转载自www.cnblogs.com/dongkx/p/10529455.html
今日推荐