获取每月的天数

第一种方法,自己写方法判断:

//是不是闰年

private BooleanisRunYear(int year) {

return (year %4 ==0) && (year %100 !=0) || (year %400 ==0);

}

//是不是二月

private BooleanisFebruary(int month) {

return month ==2;

}

//是不是30天的月份

private BooleanisHasThirtyDays(int month) {

return month ==4 || month ==6 || month ==9 || month ==11;

}

private ArrayList getDayList() {

int nowYear = Integer.valueOf(yearList.get(yearSelectIndex));

    int nowMonth = Integer.valueOf(monthList.get(monthSelectIndex))-1;

    ArrayList dayList =new ArrayList<>();

    int maxDay;

    if (!isRunYear(nowYear) && isFebruary(nowMonth)) {

maxDay =28;

    }else if (isRunYear(nowYear) && isFebruary(nowMonth)) {

maxDay =29;

    }else if (isHasThirtyDays(nowMonth)) {

maxDay =30;

    }else {

maxDay =31;

    }

for (int i =01; i <= maxDay; i++) {

dayList.add(getTwoNumber(i +""));

    }

return dayList;

}

第二种方法,用Calendar:

Map<Integer, ArrayList<String>> DAYS = new HashMap<>();

明显第二种更好用!