如何根据当前日期计算周一和周末,格式化当前日期

获取当前时间展示为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);

 

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