I want to have a live update on how many seconds have I started working on something. So I used recursive function to call itself. But however when I run, there seems to be an error as it is not updating. Following is my code:
getDiff();
function getDiff(){
var date1 = new Date("04/06/2011");
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var date2 = new Date($.now());;
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = 0;
// seconds
$("#webSeconds").html(Math.ceil(timeDiff / (1000))+" seconds");
setInterval(getDiff(),5000);
}
As you can see, I am using setInterval but nothing is happening, any advice?
setTimeout(getDiff, 5000)(which schedules the function, but does not call it). Notice that your current code does recursively call the function, unfortunately with no end.new Date(2011,5,4)noting that months are zero indexed so 5 is June.