RexxCrow
08-09-2006, 08:22 PM
Could I get some assistance with finishing this timer up, it seems to work fine, not sure if I have the timing set correct though, referring to the 1 sec timeouts and the 59 min and 59 sec hour change marker... I think that is the proper way to do it, but wanted to make sure.
I am having a prob with the hour though one the hour is reached it adds a 0 to the display per second passed, the prob is I have to wait 1 hour to pass before I can test my changes so it is very slow to figure it out on my own, was hoping somebody could point out what I am doing wrong on that part. i.e. the display would like something this just after the first hour: 00001:00:04, 00000000001:00:10, etc., until then it would like like: 59:59, and then when the hour comes I was wanting it to appear as: 1:00:01. THX.
window.onload=function(){
iT=new Date();
h=0;
document.getElementById('timer').innerHTML="00:00";
timer=setTimeout("update()",1000);
}
function update(){
clearTimeout(timer);
lapse=new Date();
timeComp=lapse.getTime()-iT.getTime();
lapse.setTime(timeComp);
m=lapse.getMinutes();
s=lapse.getSeconds();
m=pt(m);
s=pt(s);
if (m==59 && s==59){h++};
if (h>0){
document.getElementById('timer').innerHTML=h+":"+m+":"+s;
}else{
document.getElementById('timer').innerHTML=m+":"+s;
}
timer=setTimeout("update()",1000);
}
function pt(i){
if (i<10){i="0"+i};
return i
}
* Ok, just finished a new test and it appears to be working now, I stopped trying to put a leading 0 in the hour section, which I did not really want anyways, the hours looks better without that.
I am having a prob with the hour though one the hour is reached it adds a 0 to the display per second passed, the prob is I have to wait 1 hour to pass before I can test my changes so it is very slow to figure it out on my own, was hoping somebody could point out what I am doing wrong on that part. i.e. the display would like something this just after the first hour: 00001:00:04, 00000000001:00:10, etc., until then it would like like: 59:59, and then when the hour comes I was wanting it to appear as: 1:00:01. THX.
window.onload=function(){
iT=new Date();
h=0;
document.getElementById('timer').innerHTML="00:00";
timer=setTimeout("update()",1000);
}
function update(){
clearTimeout(timer);
lapse=new Date();
timeComp=lapse.getTime()-iT.getTime();
lapse.setTime(timeComp);
m=lapse.getMinutes();
s=lapse.getSeconds();
m=pt(m);
s=pt(s);
if (m==59 && s==59){h++};
if (h>0){
document.getElementById('timer').innerHTML=h+":"+m+":"+s;
}else{
document.getElementById('timer').innerHTML=m+":"+s;
}
timer=setTimeout("update()",1000);
}
function pt(i){
if (i<10){i="0"+i};
return i
}
* Ok, just finished a new test and it appears to be working now, I stopped trying to put a leading 0 in the hour section, which I did not really want anyways, the hours looks better without that.