JavaScript: JavaScript and DOM 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>DOM-based Clock</title>
<meta
http-equiv=”Content-Type”
content=”text/html;
charset=ISO-8859-1”
/>
<script
type=”text/javascript”
language=”javascript1.5”
>
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”;
clockSpan = document.getElementById(“myClock”);
clockSpan.replaceChild
(document.createTextNode(theTime),
clockSpan.firstChild);
setTimeout(“theClock()”,1000);
}
</script>
</head>
<body>
The current time is
<span id=”myClock”>
?
</span>
</body>
</html>