Angular directive/filter/service for formatting date so that it displays how long ago the given time was compared to now
i have to display the time difference from the current time in angularjs .
created time 2015-09-01T10:59:00.568Z
current time 2015-09-01T11:00:00.568Z.
can anyone know how to display 1 min ago in a chat application window.
You can do this using a 'filter' to do your formatting. In the template you just apply the filter in your expression as in the following plunker I made.
Here's the HTML :
{{currentdate - prevdate | formatDiff}} mins ago}}
And here's your filter :
app.filter('formatDiff', function() {
return function(items) {
minutes = items/60000;
return Math.round(minutes)
}
})
Subsequently, if you want to display hours, days etc. you can tweak the code in your filter accordingly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.