jQuery timer, ajax, and "nice time"

Posted by Mil on Stack Overflow See other posts from Stack Overflow or by Mil
Published on 2010-06-12T19:04:26Z Indexed on 2010/06/12 19:12 UTC
Read the original article Hit count: 254

So for this is what I've got:

$(document).ready(function () {
$("#div p").load("/update/temp.php");
function addOne() {
var number = parseInt($("#div p").html());
return number + 1;
}
setInterval(function () {
$("#div p").text(addOne());
}, 1000);
setInterval(function () {
$("#geupdate p").load("/update/temp.php");}
,10000);
});

So this grabs a a UNIX timestamp from temp.php and puts into into #div p, and then adds 1 to it every second, and then every 10 seconds it will check the original file to keep it up to speed.

My problem is that I need to format this UNIX timestamp into a format such as "1 day 3 hours 56 minutes and 3 seconds ago", while also doing all the incrementation and ajax calls. I'm not very experienced with jquery/javascript, so I might be missing something basic.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about time