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.