Moment. js makes it easy to obtain the week number of the current year and the week number of moment. js.
The code is very simple, so there is not much nonsense. The code is provided directly:
Copy codeThe Code is as follows:
/**
* The current date is the week of the current year, and a few weeks are pushed forward and backward.
* The js array stores the data of the first two weeks (five weeks in total) of the current date)
**/
Var initSearchMajorChanges = function (){
// The current date is the week of the current year, and then the weeks are pushed forward and backward. The js array stores the data of the previous two weeks (five weeks in total) of the current date)
Var vv = '2017-02-07 ';
Var vNowDate = moment (new moment (vv ). format ("YYYY-MM-DD "));//. add ('month', 0 ). add ('days ',-1 );
Var vWeekOfDay = moment (vNowDate). format ("E"); // calculate the week number of this week
Var vWeekOfDays = 7-vWeekOfDay-1;
Var vStartDate = moment (vNowDate). add ('days ', vWeekOfDays );
Var vEndDate = moment (vNowDate). add ('days ',-vWeekOfDay );
Var vStartDateNew = moment (vStartDate). add ('days ', 7 * $ scope. gWeeks );
Var vEndDateNew = moment (vEndDate). add ('days ',-(7 * $ scope. gWeeks ));
// Var vYearAndWeek = moment (vStartDate). format ("YYYY") + '-' + moment (vStartDate). format ("WW ");
SearchMajorChanges (vStartDateNew, vEndDateNew );
}
Requirements:
The js array stores the data of the first two weeks (five weeks in total) of the current date week. The above is the core code!
It is easy to use and I hope you will like it.