Apr 15

ASP 常用函数 闰年计算方法:isLeapYear()

计算闰年主要是为了判断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
%>



上面这个相对较严格匹配,再补上一个简化的版本:

 

 程序代码
<%
'功能:判断是否是闰年
Function isLeapYear(sYear)
    isLeapYear = False
    If sYear Mod 4 = 0 And (sYear Mod 100 <> 0 or (sYear Mod 100 = 0 And sYear Mod 400 = 0)) Then isLeapYear = True
End Function
%>

等等,下面还有精彩的文章哟:

to "ASP 常用函数 闰年计算方法:isLeapYear()"

Leave a Reply