package timer; /** * @author mercy * 计算月份工具类 *闰年29天平年28天 */ public class CalculateDay { public static void main(String[] args) { int year=1700; int month=2; int day= getDay(year,month); System.out.println(day); } public static int getDay(int year,int month){ int day=0; switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: day=31; break; case 4: case 6: case 9: case 11: day=30; break; case 2: day=getTwoMonthDay(year); } return day; } /** * @param year * 能被100整除且能被400整除是闰年,能被4整除的是闰年 * @return */ public static int getTwoMonthDay(int year){ int day=0; if(year%100==0){ if(year%400==0){ day=29; }else{ day=28; } }else if(year% 4==0){ day=29; }else{ day=28; } return day; } }
时间: 2024-11-06 18:46:30