package com.test; import java.util.Calendar; public class Test { /** * @param argsfsdf */ public void testIf(){ //获取当前时间 Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH )+1; int day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("今天是"+year + " 年 " + month + " 月"+ day +" 日 "); if(month == 1){ day = 31; }else if(month == 2){ day = 28; } else if(month == 3){ day = 31; } else if(month == 4){ day = 30; } else if(month == 5){ day = 31; } else if(month == 6){ day = 30; } else if(month == 7){ day = 31; } else if(month == 8){ day = 31; } else if(month == 9){ day = 30; } else if(month == 10){ day = 31; } else if(month == 11){ day = 30; } else if(month == 12){ day = 31; } System.out.println(day); } public static void main(String args[]){ Test t = new Test(); t.testIf(); } }
java
最新推荐文章于 2024-01-06 14:11:40 发布