标签:print tin util time() void get etc nbsp 方法
calendar是日历类,该类是抽象类不能被实例化
1 public class CalendarTest { 2 /* 3 创建对象和方法的使用 4 */ 5 public static void main(String[] args) { 6 //实例化对象 7 Calendar instance = Calendar.getInstance(); 8 //说明是子类实现class java.util.GregorianCalendar 9 System.out.println(instance.getClass()); 10 //get方法得到本月的日 11 int day = instance.get(Calendar.DAY_OF_MONTH); 12 System.out.println(day); 13 //set设置日为10 14 instance.set(Calendar.DAY_OF_MONTH,10); 15 int day1 = instance.get(Calendar.DAY_OF_MONTH); 16 System.out.println(day1); 17 //add添加3天 18 instance.add(Calendar.DAY_OF_MONTH,3); 19 int day2 = instance.get(Calendar.DAY_OF_MONTH); 20 System.out.println(day2); 21 //把日历类转换为date 22 Date time = instance.getTime(); 23 System.out.println(time); 24 //把date转为日历 25 Date date = new Date(); 26 instance.setTime(date); 27 int i = instance.get(Calendar.DAY_OF_MONTH); 28 System.out.println(i); 29 } 30 }
标签:print tin util time() void get etc nbsp 方法
原文地址:https://www.cnblogs.com/aikang525/p/11128445.html