1、

//判断一年是否为闰年

public boolean isYear(int year){

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

}

 

2、

//获得某一年的总天数

public int getSumDays(int year){

    return (isYear(year)? 366: 365);

}

3、

//获得某年、某月的最大天数

public int getMaxDay(int year,int month){

    switch(month)

    {

    case 1:

    case 3:

    case 5:

    case 7:

    case 8:

    case 10:

    case 12:

        return 31;        

    case 4:

    case 6:

    case 9:

    case 11:

        return 30;    

    case 2:

        return (isYear(year)? 29: 28);    

    default:

        return -1;

    }

}

 

4、

//获得某年、某月、某日是这一年的第几天

public int getDays(int year,int month,int day){

    int sum = 0;

    

    for(int i = 1; i < month ; i++){

        sum += getMaxDay(year,i);

    }

    

    return sum+day;

}