我正在使用角矩庫。出於某種原因,在使用amTimeAgo
時,它將超過25天的任何內容視爲一個月。amTimeAgo過濾器計算月份錯誤
在這個例子中,我使用JS的時間來計算當前時間25,26,27天。然後使用amTimeAgo
來計算從現在開始的持續時間。
angular.module('timeApp', ['angularMoment'])
.controller('mainController', [ '$scope', function($scope) {
$scope.today = new Date();
$scope.parsedToday = moment($scope.today).format('MM/DD/YYYY hh:mm A');
$scope.days25FromNow = moment($scope.today).subtract({days: 25}).format('MM/DD/YYYY hh:mm A');
$scope.days26FromNow = moment($scope.today).subtract({days: 26}).format('MM/DD/YYYY hh:mm A');
$scope.days27FromNow = moment($scope.today).subtract({days: 27}).format('MM/DD/YYYY hh:mm A');
}]);
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-moment/1.0.0/angular-moment.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="container" ng-app="timeApp" ng-controller="mainController as main">
<div>
<h2>AmTimeAgo Error in Over 25 days</h2>
<h3>The Time is {{ parsedToday}}</h3>
<p>25 Days From Now - {{days25FromNow}} <br>
Original AM Time Ago - {{days25FromNow | amTimeAgo}} <br>
Expect - 25 days ago
</p>
<p>26 Days From Now - {{days26FromNow}} <br>
Original AM Time Ago - {{days26FromNow | amTimeAgo}}<br>
Expect - 26 days ago
</p>
<p>27 Days From Now - {{days27FromNow}} <br>
Original AM Time Ago - {{days27FromNow | amTimeAgo}}<br>
Expect - 27 days ago
</p>
</div>
</div>
</body>
</html>
同樣的例子 - http://plnkr.co/edit/DZqqI5BC2XNrITThLCS7?p=preview
有沒有辦法,我可以設置所以它計算30天爲一個月的配置?或者是這個錯誤?我正在審閱他們的文檔和來源,我似乎無法找到將其更改爲30天的地方。
謝謝!
非常感謝。我肯定是在看錯地方(角度矩),但這是來自moment.js本身的繼承設置。使用此過濾器時,我還會記住您的格式化建議。再次感謝。 – devtye