public static boolean isLeapYear(int year) {
if ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0))
return true;
else
return false;
}
public void getDate(String newYear){
int MONTH_LENGTH[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int LEAP_MONTH_LENGTH[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int daymax = isLeapYear(newYear) ? LEAP_MONTH_LENGTH[month - 1] : MONTH_LENGTH[month - 1];}
if ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0))
return true;
else
return false;
}
public void getDate(String newYear){
int MONTH_LENGTH[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int LEAP_MONTH_LENGTH[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int daymax = isLeapYear(newYear) ? LEAP_MONTH_LENGTH[month - 1] : MONTH_LENGTH[month - 1];}
先求的一年的天数,有365和366天,这样就可以确定2月是多少天了,其他的你应该知道
某月=2;//求1998-2月的天数
int 天数=1;
Date date = new Date(某年,某月,1);//不推荐使用date类,可以换别的类,比如calendar
while (date.getdate()==某月) {
天数 ++;
date.setdate(date.getdate() + 1);//日加1,如果已经到下个月了就退出循环
//date类好像也没有setDate方法,目的是日期加一天
}得到的天数就是1998-2的天数
while(date.getMonth()==某月) {
c.set(java.util.Calendar.YEAR, 2003);
for (int i = 0; i < 12; i++) {
c.set(java.util.Calendar.MONTH, i);
int n = c.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
System.out.println(n);
}
把上面的2003换成随便什么年。
n是天数