网友俱乐部 » 网络编程 » JSP教程 » 功能非常全面的日期处理函数

2008-7-16 00:11 轻骑兵
功能非常全面的日期处理函数

<script language=javascript>
function fnSubmit(strPage)
{
  document.forms[0].action= strPage
  document.forms[0].submit()   
}
</script>
<%
call writedropdowns
Sub writeDropDowns()
  Dim strSelfLink
  strSelfLink = request.servervariables("SCRIPT_NAME")
  response.Write "<form name=dates method=post>" &amp; vbcrlf
  response.Write MonthDropDown("month1",False,request("month1"),strSelfLink) &amp; " " &amp; DayDropDown("day1", "",getDaysInMonth(request("month1"),request("year1")),request("day1")) &amp; " " &amp; YearDropDown("year1","","", request("year1"),strSelfLink) &amp; vbcrlf
  response.Write "</form>"    &amp; vbcrlf
End Sub
        
Function MonthDropDown(strName, blnNum, strSelected, strSelfLink)
  Dim strTemp, i, strSelectedString            
  strTemp = "<select name="" &amp; strName&amp; "" onchange="javascript: fnSubmit(" &amp; chr(34) &amp; strSelfLink &amp; chr(34) &amp; ")">" &amp; vbcrlf
  strTemp = strTemp &amp; "<option value="" &amp; 0 &amp; "">" &amp; "Month" &amp; "</option>" &amp; vbcrlf            
  For i = 1 To 12
    If strSelected = CStr(i) Then
    strSelectedString = "Selected"
    Else
    strSelectedString = ""
    End If
            
    If blnNum Then
      strTemp = strTemp &amp; "<option value="" &amp; i &amp; "" " &amp; strSelectedString &amp; " >" &amp; i &amp; "</option>" &amp; vbcrlf            
    Else
    strTemp = strTemp &amp; "<option value="" &amp; i &amp; "" " &amp; strSelectedString &amp; " >" &amp; MonthName(i) &amp; "</option>" &amp; vbcrlf            
    End If
  Next                    
  strTemp = strTemp &amp; "</select>" &amp; vbcrlf   
  MonthDropDown = strTemp
End Function
Function YearDropDown(strName, intStartYear, intEndYear, strSelected, strSelfLink)
  
  Dim strTemp, i, strSelectedString   
  
  If intStartYear = "" Then
    intStartYear = Year(now())
  End If   
   
  If intEndYear = "" Then
    intEndYear = Year(now()) + 9
  End If
   
  strTemp = "<select name="" &amp; strName&amp; "" onchange="javascript: fnSubmit(" &amp; chr(34) &amp; strSelfLink &amp; chr(34) &amp; ")">" &amp; vbcrlf            
  strTemp = strTemp &amp; "<option value="" &amp; 0 &amp; "">" &amp; "Year" &amp; "</option>" &amp; vbcrlf            
  For i = intStartYear To intEndYear        
    If strSelected = CStr(i) Then
      strSelectedString = "Selected"
    Else
      strSelectedString = ""
    End If
    strTemp = strTemp &amp; "<option value="" &amp; i &amp; "" " &amp; strSelectedString &amp; " >" &amp; i &amp; "</option>" &amp; vbcrlf                           
   Next                    
   strTemp = strTemp &amp; "</select>" &amp; vbcrlf   
   YearDropDown = strTemp
End Function
Function DayDropDown(strName, intStartDay, intEndDay, strSelected )
    Dim strTemp, i, strSelectedString   
    If intStartDay = "" Then
      intStartDay = 1
    End If   
   
    If intEndDay = "" Then
      intEndDay = getDaysInMonth(Month(now()),Year(now()))
    End If
   
    strTemp = "<select name="" &amp; strName&amp; "">" &amp; vbcrlf            
    strTemp = strTemp &amp; "<option value="" &amp; 0 &amp; "">" &amp; "Day" &amp; "</option>" &amp; vbcrlf            
    For i = intStartDay To intEndDay
      If strSelected = CStr(i) Then
        strSelectedString = "Selected"
      Else
        strSelectedString = ""
      End If
      strTemp = strTemp &amp; "<option value="" &amp; i &amp; "" " &amp; strSelectedString &amp; " >" &amp; i &amp; "</option>" &amp; vbcrlf                           
    Next                    
    strTemp = strTemp &amp; "</select>" &amp; vbcrlf   
    DayDropDown = strTemp
End Function
Function getDaysInMonth(strMonth,strYear)
        Dim strDays     
    Select Case CInt(strMonth)
        Case 1,3,5,7,8,10,12:
        strDays = 31
        Case 4,6,9,11:
           strDays = 30
        Case 2:
        If  ( (CInt(strYear) Mod 4 = 0  And  CInt(strYear) Mod 100 <> 0)  Or ( CInt(strYear) Mod 400 = 0) ) Then
          strDays = 29
        Else
          strDays = 28
        End If   
        "Case Else:
    End Select
        
    getDaysInMonth = strDays
End Function   
%>   

页: [1]


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.