asp 中求某个月份的最后一天
来源:百度知道 编辑:UC知道 时间:2024/06/07 08:44:10
********代码******
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