http://dev.csdn.net/article/38/38464.shtm

解决方案 »

  1.   

    本人用的 
    <!--
    Function Name   : 日期選擇程式
    Desc            : 
    Create By       : Mabel Deng 
    Date            : 04/12/03
    Modify By       : 
    Last Modify Date: 
    -->
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <title><%=myTitle%></title>
    </head>
    <body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">
    <%
    '*******************************************************
    '* ASP 101 Sample Code - http://www.asp101.com *
    '* *
    '* This code is made available as a service to our *
    '* visitors and is provided strictly for the *
    '* purpose of illustration. *
    '* *
    '* Please direct all inquiries to [email protected] *
    '*******************************************************
    %> <%
    ' ***Begin Function Declaration***
    ' New and improved GetDaysInMonth implementation.
    ' Thanks to Florent Renucci for pointing out that I
    ' could easily use the same method I used for the
    ' revised GetWeekdayMonthStartsOn function.
    Function GetDaysInMonth(iMonth, iYear)
    Dim dTemp
    dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
    GetDaysInMonth = Day(dTemp)
    End Function' Previous implementation on GetDaysInMonth
    'Function GetDaysInMonth(iMonth, iYear)
    ' Select Case iMonth
    ' Case 1, 3, 5, 7, 8, 10, 12
    ' GetDaysInMonth = 31
    ' Case 4, 6, 9, 11
    ' GetDaysInMonth = 30
    ' Case 2
    ' If IsDate("February 29, " & iYear) Then
    ' GetDaysInMonth = 29
    ' Else
    ' GetDaysInMonth = 28
    ' End If
    ' End Select
    'End FunctionFunction GetWeekdayMonthStartsOn(dAnyDayInTheMonth)
    Dim dTemp
    dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
    GetWeekdayMonthStartsOn = WeekDay(dTemp)
    End FunctionFunction SubtractOneMonth(dDate)
    SubtractOneMonth = DateAdd("m", -1, dDate)
    End FunctionFunction AddOneMonth(dDate)
    AddOneMonth = DateAdd("m", 1, dDate)
    End Function
    ' ***End Function Declaration***
    Dim dDate ' Date we're displaying calendar for
    Dim iDIM ' Days In Month
    Dim iDOW ' Day Of Week that month starts on
    Dim iCurrent ' Variable we use to hold current day of month as we write table
    Dim iPosition ' Variable we use to hold current position in table
    ' Get selected date. There are two ways to do this.
    ' First check if we were passed a full date in RQS("date").
    ' If so use it, if not look for seperate variables, putting them togeter into a date.
    ' Lastly check if the date is valid...if not use today
    If IsDate(Request.QueryString("date")) Then
    dDate = CDate(Request.QueryString("date"))
    Else
    If IsDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year")) Then
    dDate = CDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year"))
    Else
    dDate = Date()
    ' The annoyingly bad solution for those of you running IIS3
    If Len(Request.QueryString("month")) <> 0 Or Len(Request.QueryString("day")) <> 0 Or Len(Request.QueryString("year")) <> 0 Or Len(Request.QueryString("date")) <> 0 Then
    Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
    End If
    ' The elegant solution for those of you running IIS4
    'If Request.QueryString.Count <> 0 Then Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
    End If
    End If'Now we've got the date. Now get Days in the choosen month and the day of the week it starts on.
    iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
    iDOW = GetWeekdayMonthStartsOn(dDate)%>
    <!-- Outer Table is simply to get the pretty border-->
    <TABLE BORDER=10 CELLSPACING=0 CELLPADDING=0 bordercolor="#9999cc">
    <TR>
    <TD>
    <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 BGCOLOR=#BDE4B7 bordercolor="#cdeac9">
    <TR>
    <TD BGCOLOR="#f0f0f0" ALIGN="center" COLSPAN=7>
    <TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0>
    <TR>
    <TD ALIGN="right"><A HREF="<%=targetAsp%>?date=<%=SubtractOneMonth(dDate) %>"><FONT COLOR=#F05E17 SIZE="-1"><<</FONT></A></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B><%=MonthName(Month(dDate)) & " " & Year(dDate) %></B></FONT></TD>
    <TD ALIGN="left"><A HREF="<%=targetAsp%>?date=<%=AddOneMonth(dDate) %>"><FONT COLOR=#F05E17 SIZE="-1">>></FONT></A></TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    <TR BGCOLOR =#CFD23E>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Sun</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Mon</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Tue</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Wed</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Thu</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Fri</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    <TD ALIGN="center"><FONT COLOR=#F05E17><B>Sat</B></FONT><BR><IMG 
    SRC="./images/spacer.gif" WIDTH=30 HEIGHT=1 BORDER=0></TD>
    </TR>
    <%
    ' Write spacer cells at beginning of first row if month doesn't start on a Sunday.
    If iDOW <> 1 Then
    Response.Write vbTab & "<TR>" & vbCrLf
    iPosition = 1
    Do While iPosition < iDOW
    Response.Write vbTab & vbTab & "<TD> </TD>" & vbCrLf
    iPosition = iPosition + 1
    Loop
    End If' Write days of month in proper day slots
    iCurrent = 1
    iPosition = iDOW
    Do While iCurrent <= iDIM
    ' If we're at the begginning of a row then write TR
    If iPosition = 1 Then
    Response.Write vbTab & "<TR HEIGHT=""1"">" & vbCrLf
    End If' If the day we're writing is the selected day then highlight it somehow.
    dim fmtDate 
    fmtDate = Year(dDate) & "/"
    if Cint(Month(dDate))  < 10 then
    fmtDate = fmtDate & "0" & Month(dDate) & "/"
    else
    fmtDate = fmtDate & Month(dDate) & "/"
    end if
    if Cint(iCurrent) < 10 then 
    fmtDate = fmtDate & "0" & cstr(iCurrent)  
    else
    fmtDate = fmtDate & cstr(iCurrent)  
    end if
    If iCurrent = Day(dDate) Then
    Response.Write vbTab & vbTab & "<TD BGCOLOR=#00FFFF><A HREF=""javascript:RetVal('"& fmtDate &"');""><FONT SIZE=""-1"" style=""text-align:center""><B>" & iCurrent & "</B></FONT><BR><BR><IMG SRC=""./images/spacer.gif"" WIDTH=30 HEIGHT=1 BORDER=0></TD>" & vbCrLf
    Else
    Response.Write vbTab & vbTab & "<TD><A HREF=""javascript:RetVal('"& fmtDate &"');""><FONT SIZE=""-1"" style=""text-align:center"">" & iCurrent & "</FONT></A><BR><BR><IMG SRC=""./images/spacer.gif"" WIDTH=30 HEIGHT=1 BORDER=0></TD>" & vbCrLf
    End If' If we're at the endof a row then write /TR
    If iPosition = 7 Then
    Response.Write vbTab & "</TR>" & vbCrLf
    iPosition = 0
    End If' Increment variables
    iCurrent = iCurrent + 1
    iPosition = iPosition + 1
    Loop' Write spacer cells at end of last row if month doesn't end on a Saturday.
    If iPosition <> 1 Then
    Do While iPosition <= 7
    Response.Write vbTab & vbTab & "<TD> </TD>" & vbCrLf
    iPosition = iPosition + 1
    Loop
    Response.Write vbTab & "</TR>" & vbCrLf
    End If
    %>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    <BR>
    <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN="center">
    <FORM ACTION="<%=targetAsp%>" METHOD=post></FORM>
    </TD></TR></TABLE>
    </body>
    </html>