A simple running clock in javascript

A simple running clock in javascript

Here I show how to code for a simple digital clock in javascript. The advantage of javascript is that it is only a client side scripting language. 

Here’s the code…

<html>

<head>

<title></title>

<script type=”text/javascript”>



function getClock()

{

var clock = new Date();

var hours12;

var ampm = “AM”;

var hours24 = clock.getHours();

var minutes = clock.getMinutes();

var seconds = clock.getSeconds();



if (hours24>=13)

{

hours12 = hours24 – 12;

ampm = “PM”;

}

else if (hours24==12)

{

hours12 = 12;

ampm = “PM”;

}

else if (hours24==0)

{

hours12 = 12;

}

else

{

hours12 = hours24;

}

if(hours12<10)

{

hours12 =”0″+hours12;

}



if (minutes<10)

{



minutes = “0” + minutes;

}

if(seconds<10)

{

seconds =”0″+seconds;

}

var time = hours12 + ” : ” + minutes +” : “+ seconds + ” ” + ampm;

document.title = time;

document.getElementById(“clock”).innerHTML = time;

timer = setTimeout(“getClock()”,1000);

}



</script>

<body onload=”getClock()”>

<div id=”clock”></div>

</body>
</html>


Don’t forget to put some styles on to this clock. For look more pretty







Thankx for visit meh:::::::::: :D :D

Comments

Popular posts from this blog

A Javascript Program To make (open new window and close that window) button in your web browser.