<html>
<head>
<script type="text/javascript">
function gettime()
{
var time=new Date()
var hour=time.getHours()
var minute=time.getMinutes()
var text=hour+':'+ minute
return text
}
function nameofmonth(month)
{
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
return monthname[month]
}
function monthdays(month,year)
{
var daysofmonth=new Array(31,28,31,31,30,31,31,31,30,31,30,31)
if(year%4==0)
daysofmonth[1]=29
return daysofmonth[month]
}
function table()
{
var now=new Date()
var hour=now.getHours()
var minute=now.getMinutes()
var second=now.getSeconds()
var date=now.getDate()
var month=now.getMonth()
var year=now.getFullYear()
now.setFullYear(year,month,1)
var firstday=now.getDay()
var monthname=nameofmonth(month)
var daysofmonth=monthdays(month,year)
if(firstday>0)
var k=-(firstday-1)
else
k=1
var table="<table border=5 cellspacing=9 cellpadding=13>"
table +="<th colspan=7>"+monthname+" "+date+"th</th>"
table +="<tr><th>sun</th><th>mon</th><th>tue</><th>wed</th><th>thu</th<th>fri</th><th>sat</th></tr>"
for(var i=0;i<5;i++)
{
table+="<tr>"
for(var j=0;j<7;j++)
{
if(k<=daysofmonth && k>0)
{ if(k==date)
table+='<td bgcolor="aqua">'+k+'<br>'+gettime()+ '</td>'
else
table+='<td>'+k+'</td>'
k=parseInt(k)
}
else
table+="<td></td>"
k++
}
table+="</tr>"
}
table+="</table>"
document.write(table)
}
</script>
</head>
<body onload="table()">
</body >
</html>
這是我一個月的完整的代碼也calender.it時間顯示今天的date.the GETTIME函數返回當前時間。但時間是statik.To讓時間動態我應該怎麼辦?請幫助...儘快我怎樣才能讓我的數字時鐘動態?看看我的代碼
'一年%4 == 0'不足以測試是否一年是閏年。 – ThiefMaster
@ThiefMaster:直到2100年他們才安全。 – georg