Js获取本周、上周、本月、上月的开始日期、结束日期

 var now = new Date();                    //当前日期   

 var now­Day­OfWeek = now.getDay();         //今天本周的第几天    

var now­Day = now.getDate();              //当前日    

var now­Month = now.getMonth();           //当前月   

 var nowYear = now.getYear();             //当前年

 //今天   

 var getCur­rent­Date = new Date(nowYear, now­Month, nowDay); 

   var getCur­rent­Date  = formatDate(getCurrentDate)
    //昨天   

 var getYes­ter­day­Date = new Date(nowYear, now­Month, now­Day — 1); 

   var getYes­ter­day­Date =  formatDate(getYesterdayDate);
    //获得本周的开始日期  

  var getWeek­Start­Date = new Date(nowYear, now­Month, now­Day — nowDayOfWeek); 

  var getWeek­Start­Date =  formatDate(getWeekStartDate);  

  //获得本周的结束日期   

 var getWeek­End­Date = new Date(nowYear, now­Month, now­Day + (6 — nowDayOfWeek));

    var getWeek­End­Date =  formatDate(getWeekEndDate);

    //获得上周的开始日期

    var getUp­Week­Start­Date = new Date(nowYear, now­Month, now­Day — now­Day­OfWeek ‑7);  

  var getUp­Week­Start­Date =  formatDate(getUpWeekStartDate);
    //获得上周的结束日期  

  var getUp­Week­End­Date = new Date(nowYear, now­Month, now­Day + (6 — now­Day­OfWeek — 7)); 

 var getUp­Week­End­Date =  formatDate(getUpWeekEndDate);

    //获得本月的开始日期 

   var get­Month­Start­Date = new Date(nowYear, now­Month, 1); 

  var get­Month­Start­Date =  formatDate(getMonthStartDate);
    //获得本月的结束日期   

 var get­Mon­thEnd­Date = new Date(nowYear, now­Month, getMonthDays(nowMonth)); 

   var get­Mon­thEnd­Date =  formatDate(getMonthEndDate);
    //获得上月开始时间 

   var get­Last­Month­Start­Date = new Date(nowYear, last­Month, 1); 

  var get­Last­Month­Start­Date = formatDate(getLastMonthStartDate);
    //获得上月结束时间   

 var get­Last­Mon­thEnd­Date = new Date(nowYear, last­Month, getMonthDays(lastMonth)); 

   var get­Last­Mon­thEnd­Date = formatDate(getLastMonthEndDate);

为您推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注