I was in need of timer to mark an important decision; I did what most of us would do - search on the internet. I found quite a few of them, but I didn’t like any of them. Some of them were unnecessarily complicated; a couple of others weren’t easily understandable; most of them were using approximation (esp. for months and years).

My requirement was that the timer should be simple and which counts time exactly the same way we humans do. So I decided to write one myself. Before going into the details, I wanted it for my homepage.

JavaScript CountUp Timer -

This script is very simple; it takes a date to count the time from, an ID to put the timer and a message to append to the timer. It is also possible to have more than one timer on a page - check the demo link given at the end of this post.

JavaScript CountUp Timer v2.0 [code lang=“javascript”] <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> JavaScript CountUp Timer - Praveen Lobo

Contents of this DIV will be replaced by the timer
[/code]

Call me paranoid; I like bug-free code, who wouldn’t?

If you noticed the version, it is v2.0?! It is. Initially I had slightly different idea to update the counter every second. Though it seemed to work fine, I could think of a case where it would break. numOfDays[] is set initially when the timer starts. If the browser is kept open for a long time (really long time!), numOfDays[1] could become invalid. This could have been fixed easily in v1.0 itself, but I rewrote it to make it even simpler. Have a look at v1.0 below if you want to.

JavaScript CountUp Timer v1.0 [code lang=“javascript”] <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
JavaScript CountUp Timer - Praveen Lobo

Contents of this DIV will be replaced by the timer
[/code]

I have created a page to demonstrate the timer - demo (I have included another kind of timer in the middle of the page where each unit is independent of other; this uses approximation to calculate months/years)

In case of any issues/doubts/suggestions or you just want to appreciate :o), feel free to leave a comment.