当前位置:编程学习 > asp >>

asp判断闰年代码大全

asp编程如何判别闰年 

闰年判别

<%

if Request.Form("cal")="y" then n=Cint(Request.form("me"))  

if ((n mod 4=0) and (n mod 100<>0)) or (n mod 400=0) then               

Response.Write n & "是闰年!               "           

else               

Response.Write n&"不是闰年。               "           

end if       

end if  

%>       

<form method="post" action="zzzyk.com.asp">         

输入年份:           

<input type="text" name="me" size="5">           

<input type=hidden name=cal value=y>           

<input type="submit" name="Submit" value="提交">       

</form> 

-----------------------

计算闰年主要是为了判断2月份的天数,一般闰年2月份是29天,平年2月份是28天。计算闰年的算法非常简单,即:能被400整除,或者能被4整除而不能被100整除。
算法如下:

 function isLeapYear(pYear)
    set oreg=new RegExp
    oreg.Pattern="^\d{4}$"
    if not oreg.Test(pYear) then
        isLeapYear=false
        exit function
    end if
    oYear=clng(pYear)
    if ((oYear mod 4=0 and oYear mod 100<>0) or oYear mod 400=0) then
       isLeapYear=true
    else
       isLeapYear=false
    end if
 end function

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,