The main purpose is to familiarize yourself with the date object in javascript. The html code is as follows:
The Code is as follows:
The javascript code is as follows: Time Display format: 12:09:34 on Tuesday
The Code is as follows:
Function startTime (){
Try {
Var today = new Date ();
Var year = today. getFullYear ();
Var month = checkNum (today. getMonth () + 1 );
Var date = checkNum (today. getDate ());
Var day = today. getDay ();
Var hour = checkNum (today. getHours ());
Var minute = checkNum (today. getMinutes ());
Var second = checkNum (today. getSeconds ());
Switch (day ){
Case 1:
Day = "1 ";
Break;
Case 2:
Day = "2 ";
Break;
Case 3:
Day = "3 ";
Break;
Case 4:
Day = "4 ";
Break;
Case 5:
Day = "5 ";
Break;
Case 6:
Day = "6 ";
Break;
Case 7:
Day = "day ";
Break;
}
Var fullTime = year + "-" + month + "-" + date + "" + "Week" + day + "+ hour +": "+ minute + ": "+ second;
Document. getElementById ("showTime"). innerHTML = fullTime;
SetInterval ('starttime () ', 1000 );
} Catch (e ){
Alert (e. description );
}
}
Function checkNum (num ){
If (num <10 ){
Num = "0" + num;
}
Return num;
}