JavaScript Tutorial JavaScript Examples JQuery Tutorial CSS Tutorial HTML Tutorial About Us

Javascript Clock


This JavaScript clock is courtesy of Gordon McComb. You may use or modify this script freely as long as you include the copyright notice in your script

The Script
<script>
var time = new Date().getTime();
$(document.body).bind("mousemove keypress", function(e) {
time = new Date().getTime();
});

function refresh() {
if(new Date().getTime() - time >= 60000)
window.location.reload(true);
else
setTimeout(refresh, 10000);
}

setTimeout(refresh, 10000);
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
/* Copyright 1996, by Gordon McComb. All Rights Reserved.
You may use this JavaScript example as you see fit, as long as the
copyright notice above is included in your script.

This example is from "The JavaScript Sourcebook, forthcoming 
from Wiley Computer Books. */

var Temp;
setClock();

function setClock() {
var OpenImg = '<IMG SRC="'+pathOnly(location.href)+'dg'
var CloseImg='.gif" HEIGHT=21 WIDTH=16>'
Temp = ""
now = new Date();
var CurHour = now.getHours();
var CurMinute = now.getMinutes();
now = null;
if (CurHour >= 12) {
CurHour = CurHour - 12;
Ampm = "pm";
} else
Ampm = "am";
if (CurHour == 0)
CurHour = "12"
if (CurMinute < 10)
CurMinute = "0" + CurMinute
else
CurMinute = "" + CurMinute

CurHour = "" + CurHour;
for (Count = 0; Count < CurHour.length; Count++) {
Temp += OpenImg + CurHour.substring (Count, Count+1) + CloseImg
}
Temp += OpenImg + "c" + '.gif" HEIGHT=21 WIDTH=9>'
for (Count = 0; Count < CurMinute.length; Count++) {
Temp += OpenImg + CurMinute.substring (Count, Count+1) + CloseImg
}
Temp += OpenImg + Ampm + CloseImg;
}

function pathOnly (InString) {
LastSlash=InString.lastIndexOf ('/', InString.length-1)
OutString=InString.substring (0, LastSlash+1)
return (OutString);
}

//-->
</script>
  
Your current time is:

Copyright 1996, by Gordon McComb. All Rights Reserved.
You may use this JavaScript example as you see fit, as long as the
copyright notice above is included in your script.
 



Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy