Javascript Clock Timer

by top54u.com 19 Mar, 2008
Spotlight.....

Learn the simple JavaScript example code to show the clock timer to display the current time on your web page. For displaying the clock timer you must be familiar with setTimeout function of Javascript to call the function after every specified time delays.

 

JavaScript example code for Clock Timer:

<html>


<head>


<title>JavaScript Clock Timer</title>


<script language="javascript">


    function getCurrentTime()


    {


        var currentTime = new Date();


        var hrs = currentTime.getHours();


        var mnts = currentTime.getMinutes();


        var secs = currentTime.getSeconds();


        mnts = setTwoDigits(mnts);


        secs = setTwoDigits(secs);


        document.getElementById('clockTimer').innerHTML = hrs + ":" + mnts + ":" + secs;


        var timeOut = setTimeout("getCurrentTime()",1000);


    }



    
    function setTwoDigits(digit)


    {


        if(digit<10)


        {


            digit = "0" + digit;


        }


        return digit;


    }


    </script>


</head>


<body onload="getCurrentTime()">


<div id="clockTimer"></div>


</body>


</html>

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:43:09 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....