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("是闰年");
        }
    }
        
    }

}

相关文章:

  • 2021-12-05
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-10-24
猜你喜欢
  • 2021-09-09
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-08-27
  • 2021-12-18
相关资源
相似解决方案