asp 中求某个月份的最后一天

来源:百度知道 编辑:UC知道 时间:2024/06/07 08:44:10
我想在ASP中编写一段求某个月最后一天的程序,思路是:从外部取得一个年月(如:2006-2)并已赋值给一个变量(yearmonth),然后根据yearmonth求出此月的最后一天并赋值给变量maxday,可我只会ASP,不懂JAVA,要怎么编写呀,求各位大侠帮忙。从网上找到如下代码:可不知该放在ASP程序的哪个地方,也不知道把yearmonth这个变量的值传递给下面的代码,还有不知道如果将结果赋值给:maxday,如果哪位有更好更简单的代码,欢迎提供!

********代码******
public string MonthMaxDay(long Year,long Month,int Flag)
{ //获取月份畜日
string Value,Svalue ="";DateTime Dt;int Day;
if(Month==0)
{
Month=Month+1;
Year=Year-1;
}
if (Flag>0)
{
Svalue=Year.ToString("0000")+Month.ToString("00")+"28";
for(Day=29;Day<=31;Day++)
{
try
{
Value= Month.ToString("00")+"/" + Day +"/"+Year.ToString("0000");
Dt=Convert.ToDateTime(Value);
Value=Year.ToString("0000")+Month.ToString("00")+Day ;
Svalue=Value;
}
catch(Exception

楼上的用一一列举,这样有许多无功计算,我把你的函数改了下,运行速度更快:
<%
function Maxday(YearMonth)
dim TmpDate,i
TmpDate = Trim(YearMonth) & "-"
if isdate(TmpDate & "31") then
Maxday=31
elseif isdate(TmpDate & "30") then
maxday=30
elseif isdate(TmpDate & "29") then
maxday=29
else
maxday=28
end if
end function
%>

另外还有一种做法是根据历法的算法求的最大天:
每年的1,3,5,7,8,10,12均有31天
4、6、9、11均有30天
2月闰年有29天,非闰年有28天。

<%
function tian_sum(nianyue)
nian=cint(left(nianyue,instr(nianyue,"-")-1))
yue=cint(right(nianyue,len(nianyue)-instr(nianyue,"-")))
if yue=1 or yue=3 or yue=5 or yue=7 or yue=8 or yue=10 or yue=12 then
tian_sum=31
elseif yue=4 or yue=6 or yue=9 or yue=11 then
tian_sum=30
else
if ryear(nian)=true then
tian_sum=29
elseif ryear(nian)=false then
tian_sum=28
else
tian_sum=&q