So basically i have this html file that displays a list of notification messages and i want to be able to know the difference between the time for each notification but not sure how to do it in html
所以基本上我有这个html文件,显示通知消息列表,我希望能够知道每个通知的时间之间的差异,但不知道如何在html中做到这一点
<ion-item ng-repeat="single in notifications_list track by $index" class="ng-scope" ng-class="single.read == true ? 'notification-read' : 'notification-unread'" ng-click="displayNotification(single)" style="padding:13px 16px 1px;">
<div class="notifications">
<p style="white-space:normal;font-size:16px;line-height:20px;">{{single.body}}</p>
{{(currentDate - single.time).getDays()}}
<time>{{ single.time | amCalendar:referenceTime:formats }}</time>
</div>
</ion-item>
i have already created somewhere in my code that $rootScope.currentDate = new Date();
我已经在我的代码中创建了$ rootScope.currentDate = new Date();
so e.g. 2016-05-11T10:30:48.616Z - 2016-05-10T19:14:13.487+08:00
this is basically what i want to do in html view and return the difference in days.
所以例如2016-05-11T10:30:48.616Z - 2016-05-10T19:14:13.487 + 08:00这基本上是我想在html视图中做的并返回天数的差异。
How can i do that? Pls advise
我怎样才能做到这一点?请指教
4 个解决方案
#1
0
I think this will help you, time ago angularjs plugin allow to show the time in human readable firmat....for example like few time ago,,,,,hours ago,,,,etc
我想这会对你有所帮助,很久以前angularjs插件允许在人类可读的firmat中显示时间....例如像很久以前,,,,,小时前,,,,等
#2
0
I see that you are using amCalendar, so I'm guessing you are already using the angular-moment plugin.
我看到你正在使用amCalendar,所以我猜你已经在使用angular-moment插件了。
If so, you could use the amDifference filter
如果是这样,您可以使用amDifference过滤器
So I guess you could do something like:
所以我想你可以这样做:
<time>{{ single.time | amDifference : null : 'days' }}</time>
#3
0
use use moment.js so Calculation on Dates and Times
使用moment.js所以计算日期和时间
<ion-item ng-repeat="single in notifications_list track by $index" class="ng-scope" ng-class="single.read == true ? 'notification-read' : 'notification-unread'" ng-click="displayNotification(single)" style="padding:13px 16px 1px;">
<div class="notifications">
<p style="white-space:normal;font-size:16px;line-height:20px;">{{single.body}}</p>
{{getDiff(single.time)}}
<time>{{ single.time | amCalendar:referenceTime:formats }}</time>
</div>
</ion-item>
in controller:
$scope.getDiff=function(time){
var now=moment();
return now.diff(time, 'days')
};
#4
0
you can use angular-duration-format for this purpose.
您可以使用角度持续时间格式来实现此目的。
Add angular-duration-format as your app dependency.
添加角度持续时间格式作为您的应用依赖项。
angular.module('myModule', [
'angular-duration-format'
]);
In templates you can use
在模板中,您可以使用
<p>
Time passed: {{ passed | duration:'hh:mm:ss:sss' }}<br/>
Preformatted: {{ passedPre }}
</p>
In controllers (or directives, services, anywhere)
在控制器(或指令,服务,任何地方)
angular.module('myModule').controller('exampleCtrl', function($scope, $filter) {
var durationFilter = $filter('duration');
$scope.passed = 123456789;
$scope.passedPre = durationFilter($scope.passed, 'hh:mm:ss:sss');
});
The result should be the same in both cases:
在两种情况下结果应该相同:
Time passed: 34:17:36:789
Preformatted: 34:17:36:789
#1
0
I think this will help you, time ago angularjs plugin allow to show the time in human readable firmat....for example like few time ago,,,,,hours ago,,,,etc
我想这会对你有所帮助,很久以前angularjs插件允许在人类可读的firmat中显示时间....例如像很久以前,,,,,小时前,,,,等
#2
0
I see that you are using amCalendar, so I'm guessing you are already using the angular-moment plugin.
我看到你正在使用amCalendar,所以我猜你已经在使用angular-moment插件了。
If so, you could use the amDifference filter
如果是这样,您可以使用amDifference过滤器
So I guess you could do something like:
所以我想你可以这样做:
<time>{{ single.time | amDifference : null : 'days' }}</time>
#3
0
use use moment.js so Calculation on Dates and Times
使用moment.js所以计算日期和时间
<ion-item ng-repeat="single in notifications_list track by $index" class="ng-scope" ng-class="single.read == true ? 'notification-read' : 'notification-unread'" ng-click="displayNotification(single)" style="padding:13px 16px 1px;">
<div class="notifications">
<p style="white-space:normal;font-size:16px;line-height:20px;">{{single.body}}</p>
{{getDiff(single.time)}}
<time>{{ single.time | amCalendar:referenceTime:formats }}</time>
</div>
</ion-item>
in controller:
$scope.getDiff=function(time){
var now=moment();
return now.diff(time, 'days')
};
#4
0
you can use angular-duration-format for this purpose.
您可以使用角度持续时间格式来实现此目的。
Add angular-duration-format as your app dependency.
添加角度持续时间格式作为您的应用依赖项。
angular.module('myModule', [
'angular-duration-format'
]);
In templates you can use
在模板中,您可以使用
<p>
Time passed: {{ passed | duration:'hh:mm:ss:sss' }}<br/>
Preformatted: {{ passedPre }}
</p>
In controllers (or directives, services, anywhere)
在控制器(或指令,服务,任何地方)
angular.module('myModule').controller('exampleCtrl', function($scope, $filter) {
var durationFilter = $filter('duration');
$scope.passed = 123456789;
$scope.passedPre = durationFilter($scope.passed, 'hh:mm:ss:sss');
});
The result should be the same in both cases:
在两种情况下结果应该相同:
Time passed: 34:17:36:789
Preformatted: 34:17:36:789