Moment.js Easy Implementation gets the current date is the first weeks of the year _javascript tips

Source: Internet
Author: User

The code is very simple no more nonsense, directly to the code:

Copy Code code as follows:

/**
* Implementing the current date is the week ordinal of the year, then forward and backward for a few weeks
* JS Array to save the current date before and after two weeks (a total of five weeks of data)
* */
var initsearchmajorchanges = function () {
Implement the current date is the week of the year, then forward and backward for a few weeks, JS array to save the current date before and after two weeks (a total of five weeks of data)
var vv= ' 2015-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 of the 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);
}

Demand:

JS Array saves the current date week before and after two weeks (a total of five weeks of data), the above is the core code!

The use of the method is also very simple, I hope you can enjoy.

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.