Java:计算某个月份的天数


 

Calendar calendar = Calendar.getInstance();
int year = 2007;
int month = Calendar.FEBRUARY;
int date = 1; 
calendar.set(year, month, date); //2007/2/1
int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println("Max Day: " + maxDay); 
calendar.set(2004, Calendar.FEBRUARY, 1);//2004/2/1
maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println("Max Day: " + maxDay);

你可能感兴趣的:(Java:计算某个月份的天数)