2010-11-06 38 views

回答

1

嘗試一下timeago plugin

jQuery(document).ready(function() { 
    jQuery("abbr.timeago").timeago(); 
}); 

變成這樣:

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr> 
在此

<abbr class="timeago" title="July 17, 2008">2 years ago</abbr> 

也有easydate plugin

+0

感謝:-)的TIMEAGO插件是完美的:-) – 2010-11-07 01:51:51

0

這將是一個半答案,因爲我沒有搜索插件,但我會提出一個非插件解決方案。

假設創建的元素有這樣的結構:

<div class="timestamp" data-timestamp="2007-06-09T17:46:21"> ... </div> 

現在,所有你需要做的是,定期(如每分鐘左右)全部選擇「.timestamp」元素,並設置相應的輸出:

$(".timestamp").each(function() { 
    var stamp = $(this).attr("data-timestamp"); 
    var now = new Date(); 
    // compare the stamp to the current time and set the text accordingly 
}); 
相關問題