功能非常全面的日期处理函数

1<script language="javascript">   
2function fnSubmit(strPage)   
3{   
4document.forms[0].action= strPage   
5document.forms[0].submit()   
6}   
7  
8</script>
1   
2  
3call writedropdowns   
4  
5Sub writeDropDowns()   
6Dim strSelfLink   
7strSelfLink = request.servervariables("SCRIPT_NAME")   
8response.Write "

<form method="post" name="dates">" &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>

1" & vbcrlf   
2End Sub   
3  
4  
5Function MonthDropDown(strName, blnNum, strSelected, strSelfLink)   
6Dim strTemp, i, strSelectedString   
7strTemp = "

<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 "="" &="" strselectedstring="" value='" &amp; i &amp; "'>" &amp; i &amp; "</option>" &amp; vbcrlf
Else
strTemp = strTemp &amp; "<option "="" &="" strselectedstring="" value='" &amp; i &amp; "'>" &amp; MonthName(i) &amp; "</option>" &amp; vbcrlf
End If
Next
strTemp = strTemp &amp; "</select>

 1" & vbcrlf   
 2MonthDropDown = strTemp   
 3End Function   
 4  
 5  
 6Function YearDropDown(strName, intStartYear, intEndYear, strSelected, strSelfLink)   
 7  
 8Dim strTemp, i, strSelectedString   
 9  
10If intStartYear = "" Then   
11intStartYear = Year(now())   
12End If   
13  
14If intEndYear = "" Then   
15intEndYear = Year(now()) + 9   
16End If   
17  
18strTemp = "

<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 "="" &="" strselectedstring="" value='" &amp; i &amp; "'>" &amp; i &amp; "</option>" &amp; vbcrlf
Next
strTemp = strTemp &amp; "</select>

 1" & vbcrlf   
 2YearDropDown = strTemp   
 3End Function   
 4  
 5  
 6Function DayDropDown(strName, intStartDay, intEndDay, strSelected )   
 7Dim strTemp, i, strSelectedString   
 8If intStartDay = "" Then   
 9intStartDay = 1   
10End If   
11  
12If intEndDay = "" Then   
13intEndDay = getDaysInMonth(Month(now()),Year(now()))   
14End If   
15  
16strTemp = "

<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 "="" &="" strselectedstring="" value='" &amp; i &amp; "'>" &amp; i &amp; "</option>" &amp; vbcrlf
Next
strTemp = strTemp &amp; "</select>

 1" & vbcrlf   
 2DayDropDown = strTemp   
 3End Function   
 4  
 5  
 6Function getDaysInMonth(strMonth,strYear)   
 7Dim strDays   
 8Select Case CInt(strMonth)   
 9Case 1,3,5,7,8,10,12:   
10strDays = 31   
11Case 4,6,9,11:   
12strDays = 30   
13Case 2:   
14If ( (CInt(strYear) Mod 4 = 0 And CInt(strYear) Mod 100 <> 0) Or ( CInt(strYear) Mod 400 = 0) ) Then   
15strDays = 29   
16Else   
17strDays = 28   
18End If   
19'Case Else:   
20End Select   
21  
22getDaysInMonth = strDays   
23End Function   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus