代码实例:

/**
* 获取月份的天数
* 传入的month有可能是01、02、03...或者1、2、3....当month是01这种传入情况时需要去掉开头的0,以便从数组获取数据
* 传入的year是用来判断闰年和平年中二月份的天数
*/
function getDaysInMonth(month,year){
var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
if(month == '02' || month == 2){
year = parseInt(year);
daysInMonth[1] = (((0 == year % 4) && (0 != (year % 100))) || (0 == year % 400)) ? 29 : 28;
}
var flag = month.substr(0,1);
if(flag == 0){
month = month.substr(1,1);
}
return daysInMonth[month-1];
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2021-09-11
  • 2021-07-31
  • 2022-12-23
猜你喜欢
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-07-19
相关资源
相似解决方案