Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!-- This example is from the book _JavaScript: The Definitive Guide_. -->
<!-- Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. -->
<!-- This example is provided WITHOUT WARRANTY either expressed or implied.-->
<!-- You may study, use, modify, and distribute it for any purpose. -->
<HTML>
<HEAD>
<SCRIPT>
// This function displays the time in the status line.
// Invoke it once to activate the clock; it will call itself from then on.
function display_time_in_status_line()
{
var d = new Date(); // get current time;
var h = d.getHours(); // extract hours: 0 to 23
var m = d.getMinutes(); // extract minutes: 0 to 59
var ampm = (h >= 12)?"PM":"AM"; // is it am or pm?
if (h > 12) h -= 12; // convert 24-hour format to 12-hour
if (h == 0) h = 12; // convert 0 o'clock to midnight
if (m < 10) m = "0" + m; // convert 0 minutes to 00 minutes, etc.
var t = h + ':' + m + ' ' + ampm; // put it all together
defaultStatus = t; // display it in the status line
// arrange to do it all again in 1 minute.
setTimeout("display_time_in_status_line()", 60000); // 60000 ms in 1 minute
}
</SCRIPT>
</HEAD>
<!-- Don't bother starting the clock 'till everything is loaded. The
-- status line will be busy with other messages during loading, anyway -->
<BODY onLoad="display_time_in_status_line();">
<!-- The HTML document contents go here -->
<!-- O'Reilly Footer Begins Here -->
<center>
</center>
<!-- O'Reilly Footer Ends Here -->
</BODY>
</HTML>