JavaScript: Clock
Introduction
Author: Martin WarningYear: 2007
License: Free
This example will put a clock on a webpage that will show the actual time. It is dynamically modified as time passes. The clock uses the users system clock so we can't control if the clock displays the correct time.
Code
Languages:- XHTML
- JavaScript
<script language="JavaScript" type="text/javascript">12){ printTime = printTime + ' PM'; } else{ printTime = printTime + ' AM'; } // Update the element displaying the time to the user document.getElementById('showclock').innerHTML = printTime; setTimeout("Clock()",1000); } // End --> //]]> </script>Add this to the <body> tag:
<body onload="Clock()">
And add the following to somewhere in the body of your document:
<div id="showclock"></div>
Put the JavaScript function in the <head> area of the document. In the <body> we load the function which will automatically update the showclock <div>.
