getMonthDaysCount static method

int getMonthDaysCount(
  1. int year,
  2. int month
)

获取某月的天数

@param year 年 @param month 月 @return 某月的天数

Implementation

static int getMonthDaysCount(int year, int month) {
  int count = 0;
  //判断大月份
  if (month == 1 ||
      month == 3 ||
      month == 5 ||
      month == 7 ||
      month == 8 ||
      month == 10 ||
      month == 12) {
    count = 31;
  }

  //判断小月
  if (month == 4 || month == 6 || month == 9 || month == 11) {
    count = 30;
  }

  //判断平年与闰年
  if (month == 2) {
    if (isLeapYear(year)) {
      count = 29;
    } else {
      count = 28;
    }
  }
  return count;
}