Jump to content

Timer with milliseconds


pulpfiction

Recommended Posts

HiThis is the code for the timer in mm:ss, but how to do it with milliseconds in it. mm:ss:milliseconds.

var msec = 0var secs = 0var mins = 0var timerID = nullvar timerRunning = falsevar delay = 10function InitializeTimer(){    // Set the length of the timer, in seconds    secs = 00    mins = 00    StopTheClock()    StartTheTimer()}function StopTheClock(){    if(timerRunning)        clearTimeout(timerID)    timerRunning = false}function StartTheTimer(){  if (msec==990)  { 	 msec=0; 	 secs=secs+1;  }   	 if (secs==60)  { 	 secs=0; 	 mins=mins+1;  }    if (secs<10)  secs="0"+secs;  if (mins<10)  mins="0"+mins;  document.Form1.clockspot.value=mins+":"+secs+":"+msec  secs = parseInt(secs,10)  mins = parseInt(mins,10)  self.status = secs  msec = msec + 10;        //secs = secs + 1        timerRunning = true        timerID = self.setTimeout("StartTheTimer()", delay)}

Link to comment
Share on other sites

It already uses milliseconds :) Or do you mean in the status bar?

<html><head><script>var msec = 0var secs = 0var mins = 0var timerID = nullvar timerRunning = falsevar delay = 10function InitializeTimer(){   // Set the length of the timer, in seconds   secs = 00   mins = 00   StopTheClock()   StartTheTimer()}function StopTheClock(){   if(timerRunning)       clearTimeout(timerID)   timerRunning = false}function StartTheTimer(){ if (msec==990) {  msec=0;  secs=secs+1; }    if (secs==60) {  secs=0;  mins=mins+1; }  if (secs<10) secs="0"+secs; if (mins<10) mins="0"+mins; document.Form1.clockspot.value=mins+":"+secs+":"+msec secs = parseInt(secs,10) mins = parseInt(mins,10) self.status = mins+":"+secs+":"+msec msec = msec + 10;       //secs = secs + 1       timerRunning = true       timerID = self.setTimeout("StartTheTimer()", delay)}</script></head><body onload="StartTheTimer()"><form name="Form1"><input type="text" name="clockspot" /><form></body></html>

Link to comment
Share on other sites

My bad, i posted the modified code, anyways i think this timer runs slower compared to the normal clock....

It looked ok to me...What about this one, it's quite neat: http://proft.50megs.com/stopwatch.htmlEDIT Your right it does run slower, when compaired to the link above it's out.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...