I'm looking for a small MooTools library that does about what the plugin linked below does, ie dynamically update timestamps on a web page every minute or so to say "a minute ago", "2 hours ago" etc., maybe with graceful fallback for browsers with JavaScript disabled.
Don't feel like writing it myself now.
yes and it's even better :) in mootools more they have put a Date.Extras class
http://mootools.net/docs/more/Types/Date.Extras#Date:timeDiff
Wrote my own timeago code which basically uses MooTools More Date.Extras Date.timeDiffInWords()
like this in pseudo-JS (you can wrap it into a class, which I did but cannot release):
function update(element) {
enhance(element); // Enhances all new elements; skips already enhanced elements
var time = getTime(element); // Yields the time as a Date object
element.set('text', time.timeDiffInWords());
}
function updateAll() {
var i;
var elements = $$('abbr.timeago');
if ( !elements )
return;
for (i = 0; i < elements.length; i++)
update(elements[i]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.