Hi friends, today’s I want to share a JavaScript’s program. Actually few days ago I started reading JavaScript’s. I found that JavaScript’s is very essential for web programming. JavaScript’s add dynamic things to a program.
Here I give a JavaScript’s code using date object. I use some build in JavaScript’s function. Here I created a clock using JavaScript’s. Here the code for a digital clock. You can use the clock in your website. The code is very simple to understand. The clock gives you hours, minutes, seconds and A.M and P.M. So guys lets check it out.
<HEAD>
<script type=”text/javascript”>
<!–
function startclock()
{
var time=new Date();var hours=time.getHours();
var mins=time.getMinutes();
var sec=time.getSeconds();
var AandP=” “;
if (hours>=12)
AandP=”P.M.”;
else
AandP=”A.M.”;
if (hours>=13)
hours-=12;
if (hours==0)
hours=12;
if (sec<10)
sec=”0″+sec;
if (mins<10)
mins=”0″+mins;
document.clock.clockspot.value=hours+”:”+mins+”:”+sec+” “+AandP;
setTimeout(’startclock()’,1000);
} //–>
</script>
</HEAD>
<BODY onLoad=”startclock()”>
<FORM name=”clock”>
Current Time: <INPUT TYPE=”text” name=”clockspot”>
</FORM>
</BODY>
To run this code just copy the code and paste it. Open to your browser. And enjoy JavaScript’s.








4 comments
Comments feed for this article
October 18, 2008 at 5:39 pm
ttt
good post
November 24, 2008 at 10:06 am
babu
hi,
thanks for uploading this code chunk.
but it is not working properly in MAC OSX Leopard with firefox3.
why?
November 24, 2008 at 10:27 am
Saeed
thank you,
i donot know. acctually i never use MAC OSX Leopard. i donot test this code in MAC OSX. but its work on windows, linux, ubuntu very well with evry browser.
March 23, 2009 at 7:51 pm
Avi
Free JavaScript code for Digital Clock at:
http://www.etechplanet.com/post/2009/03/22/Digital-Clock-using-JavaScript.aspx