【发布时间】:2023-03-17 11:22:01
【问题描述】:
我是 Angular js 和 moment.js 的新手,我有以下代码,它给出了一周的开始日期和结束日期,例如 1 月 17 日至 1 月 23 日。但我想要 1 月 17 日星期一的所有 7 天。
我的代码
var currentDate,
weekStart,
weekEnd,
shortWeekFormat = 'MMMM Do';
function setCurrentDate(aMoment){
currentDate = aMoment,
weekStart = currentDate.clone().startOf('week'),
weekEnd = currentDate.clone().endOf('week')
}
setCurrentDate(moment());
$scope.currentWeek = function(){ return currentDate.format(shortWeekFormat); };
$scope.currentWeekStart = function(){ return weekStart.format(shortWeekFormat); };
$scope.currentWeekEnd = function(){ return weekEnd.format(shortWeekFormat); };
HTML
<h2><i class="fa fa-arrow-left"></i>Week Of {{currentWeek()}}{{currentWeekStart()}}-{{currentWeekEnd()}}<i class="fa fa-arrow-right"></i></h2>
<button ng-click="prevWeek()">previous week</button>
<button ng-click="nextWeek()">next week</button>
【问题讨论】:
-
你的问题我不清楚。您希望获得一周之间的所有 7 天并绑定到格式为“1 月 17 日,星期一”的某个地方。听起来对吗?
-
是的,这就是我想要的。也对不起我的英语@J-D
标签: angularjs date momentjs days