4-10-2010

Simple JavaScript Timer

Take advantage of Javascript's Date object to create a simple timer.

Just create a div and set it's id attribute to show_timer_div, use the other functions to start/pause/stop the timer.

<div id="show_timer_div"></div>
<a href="#" onclick="startTimer();">Start</a> | <a href="#" onclick="pauseTimer()">Pause</a> | <a href="#" onclick="resetTimer()">Stop</a>

Demo: Simple JavaScript Timer

It starts by showing 00:00/minutes:seconds then adding the seconds as they come by, if it reaches hours it starts showing 00:00:00/hours:minutes:seconds.