计算闰年的第一种方法

      public class Calendardome {

        //闰年计算 将日历设置到指定的年份   3月1日   add 向前偏移一天

            //获取天数  29为闰年
            public static void main(String[] args) {

              fun();

}

        public static void fun(){

                //使用calendar 获取一个新的实例


                Calendar c=Calendar.getInstance();


             //添加日期

      
                  c.set(2009,2,1);

   

            //偏移向前偏移一天
                c.add(Calendar.DAY_OF_MONTH, -1);

            //Get 获取天数
              int day=c.get(Calendar.DAY_OF_MONTH);


              System.out.println(day);  //打印天数


              if(day==28){      使用if 语句判断是否是闰年
                 System.out.println("不是闰年");


            }else {
                    System.out.println("是闰年");
        }
    }
        
    }

}

猜你喜欢

转载自www.cnblogs.com/hph1728390/p/10570638.html