get next week start and end using jquery and moment js

前端 未结 4 1280
灰色年华
灰色年华 2020-12-08 02:47

I searched for this question and found there is a no answer on Stackoverflow.. So I decided to answer it...

This question helps if you need to get the start/end of n

4条回答
  •  死守一世寂寞
    2020-12-08 03:36

    I used moment js for this ... u can get it from here

         /*
         all functions return moment() object.. 
    GetNextWeekStart().format('DD/MM/YYYY') to get 24/02/2014 */ function GetNextWeekStart() { var today = moment(); //edited part var daystoMonday = 0 - (today.isoWeekday() - 1) + 7; var nextMonday = today.subtract('days', daystoMonday); return nextMonday; } function GetNextWeekEnd() { var nextMonday = GetNextWeekStart(); var nextSunday = nextMonday.add('days', 6); return nextSunday; } function GetLastWeekStart() { var today = moment(); var daystoLastMonday = 0 - (1 - today.isoWeekday()) + 7; var lastMonday = today.subtract('days', daystoLastMonday); return lastMonday; } function GetLastWeekEnd() { var lastMonday = GetLastWeekStart(); var lastSunday = lastMonday.add('days', 6); return lastSunday; }

提交回复
热议问题