日期:2014-05-16  浏览次数:20713 次

for循环的问题求教
我想将当月的周一、周四循环出来,显示多少号,周几。如:

5月2日  周四
5月6日  周一
5月9日  周四
...
一直到当月最后一个周一或周四

------解决方案--------------------
for i=1 to day(dateserial(year(now),month(now)+1,1)-1)
if weekday(cdate(year(now)&"-"&month(now)&"-"& i))=1 then
reponse.write year(now)&"-"&month(now)&"-"& i & " " &"周一"&"<br>"
elseif weekday(cdate(year(now)&"-"&month(now)&"-"& i))=4 then
reponse.write year(now)&"-"&month(now)&"-"& i & " " &"周四""&"<br>"
end if
next

------解决方案--------------------

<%
Public Function DaysInMonth(ByVal y, ByVal m)
    Select Case m
        Case 1, 3, 5, 7, 8, 10, 12
            d = 31
        Case 4, 6, 9, 11
            d = 30
        Case 2
            If y / 400 = 0 Or (y / 4 = 0 And y / 100 <> 0) Then
                d = 29
            Else
                d = 28
            End If
    End Select
    DaysInMonth = d
End Function

For i = 1 To DaysInMonth(2013, 5)
    If WeekDay("2013-5-" & i, 2) = 1 Then Response.Write "2013-5-" & i & " 星期一" & "<br>"
    If WeekDay("2013-5-" & i, 2) = 4 Then Response.Write "2013-5-" & i & " 星期四" & "<br>"
Next
%>

2013-5-2 星期四
2013-5-6 星期一
2013-5-9 星期四
2013-5-13 星期一
2013-5-16 星期四
2013-5-20 星期一
2013-5-23 星期四
2013-5-27 星期一
2013-5-30 星期四