Timer StopWatch in JavaScript

L

luckyjameel

Hi Guys

Hope this message shall find u all in gr8 moods.
As i was developing a Application for Online Exam and i am in need of a
way to maintain the time for the logged in user. So Can any one let me
know how can i do this with the help of JavaScript.

Regards

Lucky
 
E

Evertjan.

wrote on 01 okt 2005 in comp.lang.javascript:
Hope this message shall find u all in gr8 moods.
As i was developing a Application for Online Exam and i am in need of a
way to maintain the time for the logged in user. So Can any one let me
know how can i do this with the help of JavaScript.

In general you cannot,
because the end of logging on is not well defined,
unless the logging off is done by the user.

If the concept is on one clientside scripted page:

start = new Date()

.......

end = new Date()

and read this NG's faq for substraction:
<http://www.merlyn.demon.co.uk/js-date1.htm#diff>

=================

If there are more pages a serverside solution is beter,
[in fact a serverside solution seems better anyway]

ASP-VBS example:

session("start")=now()

......

DurationSecs = DateDiff("s", now(), session("start") )
 
D

Dr John Stockton

JRS: In article <46B%[email protected]>,
dated Sat, 1 Oct 2005 19:05:36, seen in Dr
Clue said:
dDisplay = new Date(iDuration)
szMM=String(dDisplay.getMinutes());if(szMM.length<2)szMM="0"+szMM
szSS=String(dDisplay.getSeconds());if(szSS.length<2)szSS="0"+szSS
c.innerHTML=szMM+":"+szSS

That could more compactly be done by using something like
dDisplay.toString().match(/\d\d.\d\d /)
after checking possible toString results.

Otherwise, converting the time to seconds and using % and - and / to
convert will be brief enough and probably quicker.
setTimeout("clock()",1000)

That may not show the time once *every* second; easily fixed.

Note that UTC functions should be much faster then non-UTC.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 3 Oct 2005 18:37:23, seen in Dr
Clue said:
I could have encrypted the example too :)

Not everyone is comfortable with regx, so unless
it is the topic, I'm probably not going to use a lot
of it in the examples unless it gives a really big
bang for it's cluttered syntax.

RegExps are so useful that they should be demonstrated whenever
reasonably possible, because too many readers don't take the trouble to
begin to use them and therefore produce long and cluttered code. That's
a pretty easy RegExp to start with, given that we know that it's
handling Time.
I think the OP was looking for something to time a test or quiz,
so the resolution / precision is well within reason for
an NG example provided for someone whos technical level is that
of one who needs help with a clock.

Such a one may be rather upset to discover an error of five percent in
some computers, and I expect a smaller error in others. By all means
show that code first; but indicate that it's not ideal.

<URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top