JS 获取当前时间本周的周一

getWeekStartDate() { 
   var now = new Date(); //当前日期 
      var nowDayOfWeek = now.getDay(); //今天本周的第几天 
      var nowDay = now.getDate(); //当前日 
      var nowMonth = now.getMonth(); //当前月 
      var nowYear = now.getYear(); //当前年 
      var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek); 
      return this.formatDate(weekStartDate); 
}

formatDate(date) { 
    var myyear = date.getFullYear(); 
    var mymonth = date.getMonth()+1; 
    var myweekday = date.getDate(); 

    if(mymonth < 10){ 
       mymonth = "0" + mymonth; 
    } 
   if(myweekday < 10){ 
      myweekday = "0" + myweekday; 
   } 
   return (myyear+"-"+mymonth + "-" + myweekday); 
} 

你可能感兴趣的:(JS 获取当前时间本周的周一)