Clocks

See also Imagery Clock

There are many ways to show the time, here are but a few

<script type="text/javascript">
<!--
function showtime1(){
var now = new Date()
var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()
var timeValue = " " + (hours > 12 ? hours - 12 : hours) 
timeValue  += (minutes < 10 ? ":0" : ":") + minutes
timeValue  += (seconds < 10 ? ":0" : ":") + seconds
timeValue  += (hours >= 12 ? " p.m." : " a.m.")
timerID = setTimeout("showtime1()",1000)

document.title=timeValue //This line displays the time in the title bar

window.status =timeValue // This line displays the time in the status bar

document.clock1.button.value = timeValue // This line displays the button clock in the body section

document.getElementById("clock2").innerHTML = timeValue // This line displays the text clock in the body section

document.getElementById("clock3").innerHTML=timeValue // This line displays the time within a line of text

document.getElementById("bgclock").innerHTML = timeValue

// Delete the display lines you do not require
}

// add onload="showtime1()" to the opening BODY tag

//-->
</script>

Sample effects to use with the above script

The following example uses an image as a background with the clock positioned using CSS

<div style="position:absolute; left:260px; top:200px; width:150px; height:30px; background-image:url(yourimage.jpg)">
<div id="bgclock" style="position:relative; left:10px; top:0px;font-weight:bold; color:#8e8462; font-size:12px"></div>
</div>

Button Style

<form name="clock1"> <INPUT TYPE="button" NAME="button" style="color:#FFFF00;background-image: url(yourimage.jpg)"; SIZE="10"> </form>

Text Style

<span id="clock2" style="color:#FFCC00;background-color:black ; border:5 ridge #FFCC00"; SIZE="10"></span>

Inline time

To place  in a line of normal text, and use <span id=clock3></span> in a line of normal text :)

Some text <span id=clock3></span> text text

For Font and Background Colour changes see Buttons or Style Ref


Here is another way of telling the time without showing the clock.

<script type="text/javascript">
<!--
function showTime2() {
var now = new Date();
alert("It is now " + now.toLocaleString());
}
//-->
</script>

<form>
<INPUT TYPE="button" VALUE="Show time" onClick="javascript:showTime2()">
</form>


Pass your mouse over this text

<span id="timenow" onmouseover="(now = new Date());timenow.innerHTML=now.toLocaleString()" onmouseout="timenow.innerHTML='Pass your mouse over this text'">Pass your mouse over this text</span>