<HTML>
<HEAD>
<TITLE>JavaScript Clock</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT">
var timerID = null;
var timerRunning = false;
function stopclock(){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = ((hours < 10) ? "0" : "") + hours
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
document.form.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
function showdate() {
var date = now.getDate();
var month = now.getMonth();
var month=(month+1);
var year = now.getYear()
var dateValue = ((month < 10) ? "0" : "") + month
dateValue += ((date < 10) ? "/0" : "/") + date
dateValue += "/" + year
stopclock();
document.form.face.value = dateValue;
delay(2);
startclock();
function startclock() {
showtime();
function delay(secs) {
count = 0;
while (count < (secs * 4000)) { count++ }
</SCRIPT>
</HEAD>
<BODY onLoad="startclock()">
<FONT FACE="ARIAL" COLOR="#000080">
<CENTER>
<H1>JavaScript Clock</H1>
</CENTER>
<HR />
</FONT>
<FORM name="form">
<INPUT type="button" name="face" value="00:00:00" onClick="showdate()" /> </CENTER>
<h3>
<a href="http://www.devasp.com">DevaspTeam</a>
</h3>
</FORM>
</BODY>
</HTML>
Run your application. It will show the time on a button. You can display it anywhere or at any control.
Posted on 10/27/2007 6:37:46 AM by Prakash