Mainly to familiarize yourself with the date object in javascript
The html code is as follows:
View sourceprint? 1 <div id = "showTime"> </div>
The javascript code is as follows: Time Display format: 12:09:34 on Tuesday
View sourceprint? 01 function startTime (){
02 try {
03 var today = new Date ();
04 var year = today. getFullYear ();
05 var month = checkNum (today. getMonth () + 1 );
06 var date = checkNum (today. getDate ());
07 var day = today. getDay ();
08 var hour = checkNum (today. getHours ());
09 var minute = checkNum (today. getMinutes ());
10 var second = checkNum (today. getSeconds ());
11 switch (day ){
12 case 1:
13 day = "1 ";
14 break;
15 case 2:
16 day = "2 ";
17 break;
18 case 3:
19 day = "3 ";
20 break;
21 case 4:
22 day = "4 ";
23 break;
24 case 5:
25 day = "5 ";
26 break;
27 case 6:
28 day = "6 ";
29 break;
30 case 7:
31 day = "day ";
32 break;
33}
34 var fullTime = year + "-" + month + "-" + date + "" + "Week" + day + "+ hour +": "+ minute + ": "+ second;
35 document. getElementById ("showTime"). innerHTML = fullTime;
36 setInterval (startTime (), 1000 );
37} catch (e ){
38 alert (e. description );
39}
40}
41 function checkNum (num ){
42 if (num <10 ){
43 num = "0" + num;
44}
45 return num;
46}