I've modified the code from SO, provided by SLaks so make it work even if the user changes the time on his computer.
The time for <div id="timer"></div>
still showing the real time since the page was loaded (even if the user changes the time on his computer).
When time changed, the alert appears (please see the code below). The problem is: once time is changed, the alert appears the infinite number of times every second (but only one time is expected). Why is this happening?
$(document).ready(function () {
var start = new Date;
var end = (new Date - start) / 1000;
setInterval(function () {
if (Math.abs(end - (new Date - start) / 1000 )>1) {
start = new Date - end * 1000;
alert(Math.abs(end - (new Date - start) / 1000 ));
}
end = (new Date - start) / 1000;
$('#timer').text(end + " Seconds");
}, 100);
});