does anybody know a plugin which calculate the passage of time in jquery?
I'm looking for a plugin or codesnippet, which automatically calculates the passage开发者_运维技巧 of time. For example: you create an element with a timestamp and jquery should change the time as it grows older. Maybe you know that behavoir of the timeline in Twitter or Facebook. Does anybody know or heard something about such a thing?
Try out the timeago plugin
jQuery(document).ready(function() {
jQuery("abbr.timeago").timeago();
});
turns this:
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
in to this:
<abbr class="timeago" title="July 17, 2008">2 years ago</abbr>
There is also the easydate plugin
This is going to be a semi-answer since I didn't search for a plug-in, but I am going to propose a non-plug-in solution.
Assuming that the created elements have this structure:
<div class="timestamp" data-timestamp="2007-06-09T17:46:21"> ... </div>
Now, all you need to do is, periodically (like every minute or so) select all ".timestamp" elements and set the output accordingly:
$(".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
});
精彩评论