How to display clock using java script ?

Ranjeet_8
Posted by Ranjeet_8 under JavaScript category on | Points: 40 | Views : 1016
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Java Script Clock</title>
<script language="JavaScript" type="text/javascript">

function Curr_Time() {
var date = new Date();
var hr = date.getHours();
var mm = date.getMinutes();
var ss = date.getSeconds();
var am_pm = "AM";
if (hr > 11) {
am_pm = "PM"
}
if (hr > 12) {
hr -= 12
}
if (mm < 10) {
mm = "0" + mm
}
if (ss < 10) {
ss = "0" + ss
}
document.form1.clock.value = hr + ":" + mm + ":" + ss + " " + am_pm;
setTimeout("Curr_Time()", 100)
}

</script>
</head>
<body onload="Curr_Time()">
<form name="form1" action="">
<input type="text" name="clock" readonly="readonly" style="border: none; font-weight: bold;" />
</form>
</body>
</html>

Comments or Responses

Login to post response