JavaScript: Simple HTML and JavaScript clock
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>HTML Clock</title>
<meta
http-equiv=”Content-Type”
content=”text/html;
charset=ISO-8859-1” />
<script
type=”text/javascript”
language=”javascript”>
window.onload = theClock
function theClock()
{
now = new Date;
theTime =
(
(now.getHours() > 0
&& now.getHours()< 13
)
)
? now.getHours() : (now.getHours() == 0)
? 12 : now.getHours()-12;
theTime +=
(now.getMinutes() > 9)
? “:” + now.getMinutes() : “:0”
+ now.getMinutes();
theTime +=
(now.getSeconds() > 9)
? “:” + now.getSeconds() : “:0”
+ now.getSeconds();
theTime +=
(now.getHours() < 12)
? “ am” : “ pm”;
document.myForm.myClock.value = theTime;
setTimeout(“theClock()”,1000);
}
</script>
</head>
<body>
<form action=”#” name=”myForm”>
The current time is
<input type=”text”
name=”myClock”
readonly=”readonly”
size=”11” />
</form>
</body>
</html>