繁体   English   中英

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

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

用于格式化日期的Angular指令/过滤器/服务,以便显示给定时间与现在比较的时间

我必须在angularjs中显示当前时间的时差。

created time 2015-09-01T10:59:00.568Z

current time 2015-09-01T11:00:00.568Z.

任何人都可以知道如何在聊天应用程序窗口中显示1分钟前。

您可以使用“过滤器”进行格式化。 在模板中,您只需在表达式中应用过滤器, 就像我在下面的plunker中所做的那样。

这是HTML

{{currentdate - prevdate | formatDiff}} mins ago}}

这是你的过滤器

app.filter('formatDiff', function() {
  return function(items) {
    minutes = items/60000;
    return Math.round(minutes)
  }
})

随后,如果您想显示小时,天等,您可以相应地调整过滤器中的代码。

暂无
暂无

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

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