Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Timer StopWatch in JavaScript

Reply
Thread Tools

Timer StopWatch in JavaScript

 
 
luckyjameel@gmail.com
Guest
Posts: n/a
 
      10-01-2005
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

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      10-01-2005
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") )




--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      10-02-2005
JRS: In article <46B%e.5422$. net>,
dated Sat, 1 Oct 2005 19:05:36, seen in news:comp.lang.javascript, Dr
Clue <> posted :

> 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      10-04-2005
JRS: In article <DTe0f.6007$ et>,
dated Mon, 3 Oct 2005 18:37:23, seen in news:comp.lang.javascript, Dr
Clue <> posted :
>Dr John Stockton wrote:
>> JRS: In article <46B%e.5422$. net>,
>> dated Sat, 1 Oct 2005 19:05:36, seen in news:comp.lang.javascript, Dr
>> Clue <> posted :
>>
>>
>>> dDisplay = new Date(iDuration)
>>>szMM=String(dDisplay.getMinutes());if(szMM.leng th<2)szMM="0"+szMM
>>>szSS=String(dDisplay.getSeconds());if(szSS.leng th<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.

>
>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.
>
>> 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.

>
>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>

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stopwatch - pause counter Morten Klim Python 3 07-19-2011 08:03 PM
Stopwatch yadil VHDL 0 10-04-2008 12:41 AM
Timer/Stopwatch Lamer Perl Misc 1 03-31-2008 08:21 AM
laptop as a stopwatch with an external switch Ron C Programming 3 07-09-2006 04:41 PM
System.Timers.Timer vs. System.Threading.Timer Kelsang Wangchuk ASP .Net 0 07-31-2003 04:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57