General Question

JohnRobert's avatar

Has anyone ever created a timer using JavaScript?

Asked by JohnRobert (490points) April 28th, 2010

I am creating an HTML page that has a button that when clicked, starts a timer starting at 00:00:00 and counts upward (hh:mm:ss). This is not for a homework… I’m learning this on my own. I looked at the examples in w3schools and the JavaScript examples there either display the system time or start counting 1,2,3,4… seconds. I have not been able to find an example anywhere a counter starts at 00:00:00 begins counting upward by seconds and uses the hh:mm:ss format. I’m open to using VBscript or something else. Thank you.

Observing members: 0 Composing members: 0

3 Answers

ben's avatar

I think the easiest thing to do is just use an existing timer that uses 1,2,3,4 syntax and convert it to hh:mm:ss yourself.

It should be a fairly straightforward conversion. You’re basically just doing two mods. (I imagine there are also some existing conversions you can find, but I’d say just dive in).

andrew's avatar

To piggyback on what Ben said, you essentially need to solve: Given a number of seconds, convert that into hours, minutes, and seconds. Once you have that, you can dynamically display 2 hours, 10 minutes, 3 seconds into 2:10:03.

JohnRobert's avatar

I’ll try the conversion method. Thank you both.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther