【问题标题】:Show start date of week(ie. sunday date) from week number in angular js从角度js中的周数显示一周的开始日期(即星期日日期)
【发布时间】:2016-11-18 08:07:43
【问题描述】:
<div class="weekLabel">{{weeknumber | date filter}}</div>

输入:

周数 - 28

我想要下面的结果

一周的开始日期 - 7 月 10 日(即星期日)

<div class="weekLabel">July 10th</div>

而且,如果年份(2017),周数(2) - 它将显示 2017 周的开始日期。

请帮忙,提前谢谢。

【问题讨论】:

    标签: angularjs date filter


    【解决方案1】:

    你可以使用时刻来做到这一点:

    var app = angular.module("testApp", []);
    
    app.controller("ctrl", function($scope) {
      $scope.week = 12;
    });
    
    app.filter('getMondayOfWeek', function() {
      return function(input) {
        return input ? moment().day("Monday").week(input).format("MMM Do") : "";
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="testApp" ng-controller="ctrl">
      {{week | getMondayOfWeek}}
    </div>

    【讨论】:

    • k.感谢您的回复。
    • 使用年份来编辑过滤器并添加参数,然后检查年份是否存在并在调用 .format 之前调用 .year(theyear)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2020-03-24
    • 1970-01-01
    • 2020-03-18
    • 2012-11-27
    • 2016-04-19
    • 1970-01-01
    相关资源
    最近更新 更多