javascript判断日期是否合法

function IsDate(str)
{
    arr = str.split("-");
    if(arr.length == 3)
    {
        intYear = parseInt(arr[0],10);
        intMonth = parseInt(arr[1],10);
        intDay = parseInt(arr[2],10);
        if(isNaN(intYear) || isNaN(intMonth) || isNaN(intDay))
        {
            return false;
        }
        if(intYear > 2100 || intYear < 1900 || intMonth > 12 || intMonth < 0 || intDay > 31 || intDay < 0)
        {
            return false;
        }
        if((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay > 30)
        {
            return false;
        }
        if(intYear % 100 == 0 && intYear % 400 || intYear % 100 && intYear % 4 == 0)
        {
            if(intDay > 29)
                return false;
        }
        else
        {
            if(intDay > 28)
                return false;
        }
        return true;

    }
    return false;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页