谁能告诉JAVA我要做万年历但是有个阶段让计算输入月份距离1900年1月1日的天数怎么算

如题所述

第1个回答  2011-12-11
static int getTotalnumberofdays(int year,int month){
int total = 0;

for(int i =1900;i<year;i++){
if(leapyear(i))
total += 366;
else
total += 365;
}
for(int i=1;i<month;i++)
total += getTotalday(year,i);

//System.out.print(total);
return total;
}

static int getTotalday(int year,int month){
if(month == 1 ||month == 3 ||month == 5 ||month == 7 ||month == 8 ||month == 10 ||month == 12)
return 31;
else if(month == 4 ||month == 6 ||month == 9 ||month == 11)
return 30;
else if(month == 2)
return leapyear(year) ? 29 : 28;
return 1;
}
static boolean leapyear(int year){//判断是否为闰年
return(year%400 == 0||(year%100!=0 && year%4 == 0));
}
相似回答