package cn.hp.demo01; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date; /* * Calendar日历*/ public class Demo03 { public static void main(String[] args) { //创建日历对象 Calendar cal = Calendar.getInstance(); //设置日期 cal.set(Calendar.MONTH, 9); System.out.println("cal = "+cal); //获取日期 System.out.println(cal.get(Calendar.YEAR)+"年"); System.out.println(cal.get(Calendar.MONTH)+1+"月"); System.out.println(cal.get(Calendar.DATE)+"日"); System.out.println(cal.get(Calendar.HOUR_OF_DAY)+":"); System.out.println(cal.get(Calendar.MINUTE)+":"); System.out.println(cal.get(Calendar.SECOND)); //如何转化为Date Date date = cal.getTime(); System.out.println("date = "+date); //获取从1907到现在经过的毫秒数 System.out.println(cal.get(Calendar.MILLISECOND)); //新特性,JDK1.8新增的内容 LocalDate now1 = LocalDate.now(); System.out.println("now1 = "+now1); LocalDateTime now = LocalDateTime.now(); System.out.println("now = "+now); } }
Calendar日历
最新推荐文章于 2022-11-21 23:26:24 发布