JavaScript: Clock


Introduction

Author: Martin Warning
Year: 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: The following code is the JavaScript function:
<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>.

Example: See it in action

Downloads

Complete code:
Zip file example.zip


Kiva - loans that change lives
Printed from: http://flyinglowlander.com/ (5/20/2012)
© FlyingLowander.com 2006 - 2012

Visit http://flyinglowlander.com for more XHTML, CSS, ASP and JavaScript examples, templates and tutorials.