I want to show a digital live clock in my website

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your JavaScript question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your JavaScript question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

I want to show a digital live clock in my website

Posted
Albert Shohez
Programmer

This is a simple tutorial aims to explain how to create and put on your website a JavaScript digital clock. Create a new HTML file and name it JavaScriptClock.html. In the HEAD section of your HTML document put the code below:

<script type="text/javascript">
/* showClock() function extracts the current time hours, minutes and seconds and then displays them in the div with showText id from the BODY section */

function showClock()
{
var clock=new Date();
var hours=clock.getHours();
var minutes=clock.getMinutes();
var seconds=clock.getSeconds();
// for a nice disply we'll add a zero before the numbers between 0 and 9
if (hours<10){
hours="0" + hours;
}
if (minutes<10){
minutes="0" + minutes;
}
if (seconds<10){
seconds="0" + seconds;
}
document.getElementById('showText').innerHTML=hours+":"+minutes+":"+seconds;
t=setTimeout('showClock()',500);
/* setTimeout() JavaScript method is used to call showClock() every 1000 milliseconds (that means exactly 1 second) */
}
</script>

Next call the showClock() funtion from the BODY section of your HTML document by using the onLoad Event Handler, like in the following code:

<body onload="showClock()">
<div id="showText"></div>
</body>

Great work! Now you have a JavaScript digital clock to put on your website.

here is link below for more tutorial with colorfull clock:
http://www.webdeveloperjuice.com/2010/02/07/7-wonderful-analog-and-digital-clocks-using-css-and-javascript/

Posted
Customer

WOW, it's a nice clock, thanks

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More JavaScript Questions...

Ask Your JavaScript Question & Get An Answer Now!