Home > Web Front-end > JS Tutorial > body text

moment.js makes it easy to get the week of the current year in the current date_javascript skills

WBOY
Release: 2016-05-16 16:15:44
Original
1832 people have browsed it

The code is very simple, so I won’t go into too much nonsense, just give me the code:

Copy code The code is as follows:

/**
* * Realize that the current date is the first week of the year, and then push forward and backward by a few weeks
* The js array stores the two weeks before and after the current date (a total of five weeks of data)
**/
var initSearchMajorChanges = function(){
//Realize that the current date is the first week of the year, and then push forward and backward by a few weeks. The js array saves the two weeks before and after the current date (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 day 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);
}

Requirements:

The js array stores the two weeks before and after the current date week (a total of five weeks of data). The above is the core code!

The method of use is also very simple, I hope everyone will like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!