public class ObautDate {
/** * @param args */
public static void main(String[] args) {
// TODO Auto-generated method stub
int lastDate = 0;
lastDate = lastDate(2009,2);
System.out.println("lastDate="+lastDate);
}
//判断是不是闰年
public static boolean isLeapYear(int year){
if (year % 4 != 0)
return false;
if (year % 400 == 0)
return true;
return year % 100 != 0;
}
//取出最大日期
public static int lastDate(int year,int month){
int kLastDates[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if(month>12 || month<0){
month = 0;
}
if(month==2 && isLeapYear(year)){
return kLastDates[month] + 1;
}else{
return kLastDates[month];
}
}
}