DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JavaScript實現頁面實時顯示當前時間的簡單實例
JavaScript實現頁面實時顯示當前時間的簡單實例
編輯:關於JavaScript     
復制代碼 代碼如下:
<html>
<head>
<title>JavaScript實現頁面實時顯示當前時間</title>
</head>
<body>
<script language="javascript">
function showtime()
{
var today,hour,second,minute,year,month,date;
var strDate ;
today=new Date();
var n_day = today.getDay();
switch (n_day)
{
case 0:{
strDate = "星期日"
}break;
case 1:{
strDate = "星期一"
}break;
case 2:{
strDate ="星期二"
}break;
case 3:{
strDate = "星期三"
}break;
case 4:{
strDate = "星期四"
}break;
case 5:{
strDate = "星期五"
}break;
case 6:{
strDate = "星期六"
}break;
case 7:{
strDate = "星期日"
}break;
}
year = today.getYear();
month = today.getMonth()+1;
date = today.getDate();
hour = today.getHours();
minute =today.getMinutes();
second = today.getSeconds();
if(month<10) month="0"+month;
if(date<10) date="0"+date;
if(hour<10) hour="0"+hour;
if(minute<10) minute="0"+minute;
if(second<10) second="0"+second;
document.getElementById('time').innerHTML = year + "年" + month + "月" + date + "日 " + strDate +" " + hour + ":" + minute + ":" + second; //顯示時間
setTimeout("showtime();", 1000); //設定函數自動執行時間為 1000 ms(1 s)
}
</script>
<div id="time"></div>
<script language="javascript"> showtime();</script>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved