标签:amp 完整 bsp for turn ++ 数组 UNC ons
(1)第一步,先判断是否是闰年;
function isRN(year){
if(year%4===0 && year%100 !==0 || year%400 ===0){
return ture;
}else{
return false;
}
(2)第二步,先把平年每个月的天数组成一个数组,写出天数的计算方式;
var arr = [31,28,31,30,31,30,31,31,30,31,30,31];
var day = for(var i=0;i<month-1;i++){
day +=arr[i];
}
(3)第三步,如果是闰年,而且时间超过了二月,直接在天数上加1;(精简的完整代码)
function isRN(year){
if(year%4===0 && year%100!==0 || year%400===0){
return true;
}
return false;
}
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)){
return day+=1;
}
return day;
}
console.log(getDays(2015,3,1));
输出某年某月某日的天数
标签:amp 完整 bsp for turn ++ 数组 UNC ons
原文地址:https://www.cnblogs.com/hasher/p/9259998.html