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

how long ago the given time was compared to now

本文关键字:定时间      更新时间:2023-09-26

Angular指令/filter/service用于格式化日期,以便显示给定时间与现在相比的时间长度

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

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

有人知道如何在聊天应用程序窗口中显示1分钟前吗?

您可以使用'过滤器'来进行格式化。在模板中,您只需在表达式中应用过滤器,如下面的柱塞所示。

这是HTML:

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

这是你的过滤器:

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

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