Home  >  Article  >  Web Front-end  >  JavaScript study notes (3) Code to display the current time_Basic knowledge

JavaScript study notes (3) Code to display the current time_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:08:03919browse

The html code is as follows:

Copy code The code is as follows:



The javascript code is as follows: The time display format is: 2011-04-04 Tuesday 12:09:34
Copy code 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 = "一";
break;
case 2:
day = "二";
break;
case 3:
day = "三";
break;
case 4:
day = "四";
break;
case 5:
day = "五";
break;
case 6:
day = "六";
break;
case 7:
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;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn