/** * 实现当前日期是当年的第几周,再向前和向后推几周 * js数组保存当前日期的前后两周(共五周的数据) * */ var initSearchMajorChanges = function(){ //实现当前日期是当年的第几周,再向前和向后推几周,js数组保存当前日期的前后两周(共五周的数据) 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");//算出这周的周几 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); }
需求:
js数组保存当前日期周的前后两周(共五周的数据),以上是核心代码!
来源:https://www.cnblogs.com/Zive/p/moment.html