<%Option Explicit %>
<html>
<head>
<title>简单的日历</title>
</head>
<body>
<h3 align="center"><%=Year(Date())%>年<%=Month(Date())%>月</h3>
<table border="1" align=center>
<tr align=right>
<td>日</td>
<td >一</td>
<td>二</td>
<td>三</td>
<td >四</td>
<td >五</td>
<td >六</td>
</tr>
<%
'首先调用函数arrarDate,返回6*7的二维数组,该数组和单元格一一对应
Dim theDate
theDate=arrayDate()
'下面正式输出日历
Dim I,J
For I=1 To numrow() '从第1行到最后1行循环
Response.Write "<tr>" '开始一个新行
For J=1 To 7
If theDate(I,J)<>0 Then
If theDate(I,J)=Day(Date()) Then
Response.Write "<td><font color=blue><b>" & theDate(I,J) & "</b></font></td>" '将当天标为蓝色加粗
ElseIf J=1 OR J=7 Then
Response.Write "<td><font color=red>" & theDate(I,J) & " </font></td>" '将周六和周日标为红色
Else
Response.Write "<td>" & theDate(I,J) & "</td>" '其它日期普通显示即可
End If
Else
Response.Write "<td> </td>" '该单元格为空
End if
Next
Response.Write "</tr>" '结束这一行
Next
%>
</table>
<%
'该函数返回当月共有多少天
Function numday()
Dim IntDay,I
intDay=28 '用intDay来统计,首先赋值28
For I=29 to 31
If IsDate(Year(date()) & "-" & Month(date()) & "-" & I) Then
intDay=I '如果当天有效,返回True,则更新天数
End if
Next
numday=intDay '返回函数值
End Function
'该函数返回当月1号是星期几
Function firstDay()
firstDay=WeekDay(Year(date()) & "-" & Month(date()) & "-1") '计算1号是周几
End Function
'该函数将每一天保存到6*7的数组中,将日期填入对应的数组中
Function arrayDate()
Dim I,J,K,tempDate,arrayTemp(6,7)
For I=1 To 6 '这个嵌套循环用以给数组赋初值0
For J=1 To 7
arrayTemp(I,J)=0
Next
Next
For K=1 to numday() '从1号到最后一天循环
tempDate=Year(date()) & "-" & Month(date()) & "-" & K '返回该天日期
I=(Day(tempDate)+firstDay()-2)\7+1 '计算该天所在的行数
J=(Day(tempDate)+firstDay()-1) Mod 7 '计算该天是所在的列数
If J=0 Then J=7 '如果余数为0,表示是第7列
arrayTemp(I,J)=K '最后将当天保存到对应行列中
Next
arrayDate=arrayTemp '返回函数值
End Function
'该函数返回当月共应该显示多少行
Function numRow()
numRow=(numDay()+firstDay()-2)\7+1 '计算表格的行数,调用了前面的函数
End Function
%>
</body>
</html>