我正在使用角矩库。出于某种原因,它在使用amTimeAgo
.
在这个例子中,我使用 moment 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>
Plnkr 中的相同示例 - http://plnkr.co/edit/DZqqI5BC2XNrITThLCS7?p=preview
有没有我可以设置的配置,以便计算为每月 30 天?还是这个错误?我正在浏览他们的文档和来源,我似乎无法找到将其更改为 30 天的位置。
谢谢!