| 
一、1.Calendar抽象类1.    是什么? 是一个操作日期中的年,月,日,时,分,秒这样的单独数据的抽象类 2.    有什么用?获取日期中的年,月,日,时,分,秒这样的单独数据 3.    怎么用?通过Calendar.getInstance()获取一个子类对象。 例如: public class CalendarDemo {        publicstatic void main(String[] args) {               //创建Calendar的子类对象               Calendarc = Calendar.getInstance(); // 获取到的是子类的实例 多态               //直接打印对象名,其实是调用了对象的toString方法。               //getClass().getName() + '@' + Integer.toHexString(hashCode())               //System.out.println(c);                 System.out.println("现在的时间是:" + c.get(Calendar.YEAR)+ "年"                             +(c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DATE)                             +"日" +c.get(Calendar.HOUR) + "时" + c.get(Calendar.MINUTE)                             +"分" +c.get(Calendar.SECOND) + "秒");                 //getDays(2012);               getDays(2002);                       }          //获取任意一年的二月份有多少天        publicstatic void getDays(int year) {               //获取日历类的子类对象               Calendarc = Calendar.getInstance();                 //set方法 设置年,月,日               c.set(year,2, 1); // 设置某一年的3月1日               //怎么着让这个日期减1天呢               c.add(Calendar.DATE,-1);                 System.out.println("现在的时间是:" + c.get(Calendar.YEAR)+ "年"                             + (c.get(Calendar.MONTH) + 1) +"月" +c.get(Calendar.DATE)                             +"日" +c.get(Calendar.HOUR) + "时" + c.get(Calendar.MINUTE)                             +"分" +c.get(Calendar.SECOND) + "秒");    
 |