|
Time
- Digital Clock
Copy
and paste the code between the <body> and </body> mark-ups of your
HTML page.
Edit the
red text as required. The script can be located anywhere after it has been
declared as ID=Clock. The name Clock is used here as an example. you can use any
name after the ID= as long as you use the same name where ever it occurs on your
page.
-
You
can insert the id=Clock instruction in other opening mark-ups in
the same way as it is shown here in the paragraph (<p>) mark-up below.
-
Change the "hours+minutes+seconds+ap"
text as required to change the format of the clock output.
-
Remove
the -12 if you wish to use a 24 hour clock.
-
The
ap
represents AM or PM for use with 12 hour clock time, you may wish to remove
it when using a 24 hour clock.
This
sample code is taken from a sample Microsoft help file. It uses the local PC
clock to present the time at the PC's location rather than the web server time.
See the style page for more details
on how to change the fonts.
See
working sample below.
<p
id=Clock> </p>
<script>
<!--
function tick()
{
var hours, minutes, seconds, ap;
var intHours, intMinutes, intSeconds;
var today;
today = new Date();
intHours = today.getHours();
intMinutes = today.getMinutes();
intSeconds = today.getSeconds();
if (intHours == 0)
{
hours = "12:";
ap = "Midnight";
}
else if (intHours < 12)
{
hours = intHours+":";
ap = "A.M.";
}
else if (intHours == 12)
{
hours = "12:";
ap = "Noon";
}
else
{
intHours = intHours - 12
hours = intHours + ":";
ap = "P.M.";
}
if (intMinutes < 10)
{
minutes = "0"+intMinutes+":";
}
else
{
minutes = intMinutes+":";
}
if (intSeconds < 10)
{
seconds = "0"+intSeconds+" ";
}
else
{
seconds = intSeconds+" ";
}
timeString = hours+minutes+seconds+ap;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 100);
}
window.onload = tick;
-->
</script>
A
digital clock preview is shown below.
|