簡體   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