2 回答
已采纳
千秋此意
TA贡献158条经验 获得超187个赞
function getDaysInYear(y, m, d) { return (new Date(y, m - 1, d) - new Date(y, 0, 0)) / 86400000; } var result = getDaysInYear(2018, 1, 16); console.log(result); // => 16
QQ_随意
TA贡献51条经验 获得超28个赞
function fewDays(y,m,d) {
var arr = [31,28,31,30,31,30,31,31,30,31,30,31];
var day = 0;
if(y%4 == 0){arr[1] = 29;}
if(m > 12){m=12}
if(d >arr[m-1]){d=arr[m-1]}
for(let i = 0;i<m-1;i++){
day += arr[i];
}
return day+d
}
console.log(fewDays(2000,4,8))
console.log(fewDays(2001,5,9))
console.log(fewDays(2002,6,10))
console.log(fewDays(2003,7,11))
添加回答
举报
0/150
提交
取消