Website Scripts And Cloud Tutorials

Javascript Clock (Time)

Byadmin

Apr 3, 2014 ,

Last updated on May 17th, 2016 at 01:06 pm

Click to rate this tutorial!
[Total: 2 Average: 5]

A very simple clock using javascript. Just paste the below code and the clock will be displayed inside the div area with the id as ‘time’, We are creating an instance named TheTime = new Date; and from that we can get all values like TheTime.getHours(),TheTime.getMinutes() and TheTime.getSeconds()

Just copy the below javascript. Also refer Javascript Clock with Date Time

Oepn an HTML file and PASTE THE FOLLOWING CODE

<SCRIPT LANGUAGE="JavaScript">
function showFilled(Value) {
if(Value>9)
{
return Value;
}
else{
return '0'+Value;
}
}
function StartClock24() {
TheTime = new Date;
document.getElementById('time').innerHTML =
'The Time Is: <b>'+showFilled(TheTime.getHours()) +
":" + showFilled(TheTime.getMinutes()) +
":" + showFilled(TheTime.getSeconds());
setTimeout("StartClock24()",1000)
}
//–>
</script>
<body onload= "StartClock24()" >
<div id='time'></div>
Click to rate this tutorial!
[Total: 2 Average: 5]

Leave a Reply

Your email address will not be published.