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; }