简体   繁体   English

多久以前给定的时间与现在相比较

[英]how long ago the given time was compared to now

Angular directive/filter/service for formatting date so that it displays how long ago the given time was compared to now 用于格式化日期的Angular指令/过滤器/服务,以便显示给定时间与现在比较的时间

i have to display the time difference from the current time in angularjs . 我必须在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. 任何人都可以知道如何在聊天应用程序窗口中显示1分钟前。

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. 在模板中,您只需在表达式中应用过滤器, 就像我在下面的plunker中所做的那样。

Here's the HTML : 这是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. 随后,如果您想显示小时,天等,您可以相应地调整过滤器中的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM