In this line:
this.currentTime.setSeconds(this.currentTime.getSeconds() + 1);
the code update its currentTime
, setting it one second forward. The function is executed every second, so this effectly works like it's getting the current time.
If you change it to run ever .5 seconds, it would advance the seconds twice as fast as it should, causing it to regress when you refresh the page. If you let it run for 3 seconds, it would add 6 seconds instead, so if you reload it then the clock would seem to go back 3 seconds when getting the current time.
For some reason, the code doesn't get the current date by calling new Date()
instead (Performance? Memory management?), so you'll have to change how it moves the currentTime
forward to fix the bug, making increments in milliseconds instead of seconds, like this:
this.currentTime.setMilliseconds(this.currentTime.getMilliseconds()+500);
var timediff=(this.currentTime-this.startingdate)/500;
var secondfield=Math.floor((timediff));
var result={halfSeconds:secondfield};
this.oncountup(result);
setTimeout(function(){thisobj.start()}, 500);
That will make it increment by 1 every .5 seconds.