DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript基礎知識 >> javascript學習筆記(三)顯示當時時間的代碼
javascript學習筆記(三)顯示當時時間的代碼
編輯:JavaScript基礎知識     
html代碼如下:
復制代碼 代碼如下:
<div id="showTime"></div>

javascript 代碼如下:時間顯示格式為:2011-04-04 星期二 12:09:34
復制代碼 代碼如下:
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+" "+"星期"+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;
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved