如果将 2 , 3 ,4 作为月份数传递给函数,我想获得超过 1 个月的天数,我想获得从今天开始的总天数
function get_days_in_month(months){
days_in_month = new Date();
var y = days_in_month.getFullYear();
var m = days_in_month.getMonth();
if(months==1){
return new Date(y,m+1,0).getDate();
}
if(months==2){
// need to write code or some other logic
}
}
感谢您提前提供帮助
最佳答案
使用 for
loop :
var total = 0;
for (i = 1; i <= months; i++) {
total += new Date(y, m + i, 0).getDate();
}
return total;
关于javascript - 如何在javascript中获取2,3,4个月的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23949249/