[javascript]代码库
1 <HTML>
2 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
3 <HEAD>
4 <TITLE>时间日期篇--当前时间</TITLE>
5 </HEAD>
6
7 <BODY bgcolor="#fef4d2" onLoad=showTheCurrentTime() background="../images/background5.jpg">
8 <br>
9 <br>
10 <center>
11 <font color="ffaafa"><h2>时间日期篇--当前时间</h2></font>
12 <hr width=300>
13 <br><br>
14
15 <!-- 案例代码1开始 -->
16
17 <script LANGUAGE="JavaScript">
18
19 function showMilitaryTime() {
20 if (document.form.showMilitary[0].checked) {
21 return true;
22 }
23 return false;
24 }
25 function showTheHours(theHour) {
26 if (showMilitaryTime() || (theHour > 0 && theHour < 13)) {
27 return (theHour);
28 }
29 if (theHour == 0) {
30 return (12);
31 }
32 return (theHour-12);
33 }
34 function showZeroFilled(inValue) {
35 if (inValue > 9) {
36 return "" + inValue;
37 }
38 return "0" + inValue;
39 }
40 function showAmPm() {
41 if (showMilitaryTime()) {
42 return ("");
43 }
44 if (now.getHours() < 12) {
45 return (" am");
46 }
47 return (" pm");
48 }
49 function showTheCurrentTime() {
50 now = new Date
51 document.form.showTime.value = showTheHours(now.getHours()) + ":" + showZeroFilled(now.getMinutes()) + ":" + showZeroFilled(now.getSeconds()) + showAmPm()
52 setTimeout("showTheCurrentTime()",1000)
53 }
54 </script>
55
56
57 <!-- 案例代码1结束 -->
58
59
60 <!-- 案例代码2开始 -->
61
62 <form name="form">
63 <div align="center">
64 <center>
65 <p> <font color="#FFFFFF">
66 <!-- [Step1]: 这里可以改变显示列的长度 -->
67 <input type="text" name="showTime" size="11">
68 </font></p>
69 </center></div><div align="center"><center><p><input type="radio" name="showMilitary"
70 checked>
71 <font color="#FFFFFF">24 Hour Time<br>
72 <input type="radio" name="showMilitary">
73 12 Hour Time<br>
74 </font> </p>
75 </center></div>
76 </form>
77
78 <!--案例代码2结束 -->
79
80 </center></BODY>
81
82 </HTML>
83