首页 > 代码库 > 03-输出某年某月某日的天数(精简)

03-输出某年某月某日的天数(精简)

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>

    console.log(getDays(2015,3,1));
    function getDays(year,month,day){
        var arr = [31,28,31,30,31,30,31,31,30,31,30,31];
        for(var i=0;i<month-1;i++){
            day += arr[i];
        }
        if(month>2 && isRN(year)){
            day+=1;
        }
        return day;
    }
    function isRN(year){
        if(year%4===0 && year%100!==0 || year%400===0){
            return true;
        }
        return false;
    }



</script>
</body>
</html>

  

03-输出某年某月某日的天数(精简)