Moment. js makes it easy to obtain the week number of the current year and the week number of moment. js.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.