如何根據當前日期計算週一和週末,格式化當前日期

獲取當前時間展示爲05-08的形式,只有月日如果只有一位數就補0,兩位正常顯示 

    const myDate = new Date();
    const today = myDate.toLocaleDateString().split('/').join('-');
    let times = today.split('-');
    const Year = times[0];
    const Month = times[1];
    const Day = times[2];
    let mounth='';
    if(Month.length===1){
       mounth='0'+Month
    }else{
       mounth=Month
    }
    let day='';
    if(Day.length===1){
       day='0'+Day
    }else{
       ay=Day
    }
    const Newtoday=mounth+'-'+day;

 如何根據當前日期計算週一和週末:

const myDate = new Date();
const Monday = new Date(myDate-(myDate.getDay()-1)*86400000);
const Sunday = new Date((Monday/1000+6*86400)*1000);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章