calendar是日历类,该类是抽象类不能被实例化
public class CalendarTest { /* 创建对象和方法的使用 */ public static void main(String[] args) { //实例化对象 Calendar instance = Calendar.getInstance(); //说明是子类实现class java.util.GregorianCalendar System.out.println(instance.getClass()); //get方法得到本月的日 int day = instance.get(Calendar.DAY_OF_MONTH); System.out.println(day); //set设置日为10 instance.set(Calendar.DAY_OF_MONTH,10); int day1 = instance.get(Calendar.DAY_OF_MONTH); System.out.println(day1); //add添加3天 instance.add(Calendar.DAY_OF_MONTH,3); int day2 = instance.get(Calendar.DAY_OF_MONTH); System.out.println(day2); //把日历类转换为date Date time = instance.getTime(); System.out.println(time); //把date转为日历 Date date = new Date(); instance.setTime(date); int i = instance.get(Calendar.DAY_OF_MONTH); System.out.println(i); } }