Calendar类

 /************Calendar的使用**************/
// public static void main(String[] args) {
//  Calendar calendar = Calendar.getInstance();//不能通过new创建,只能通过getInstance获取实例
//  System.out.println("年:"+calendar.get(Calendar.YEAR));
//  System.out.println("月:"+(calendar.get(Calendar.MONTH)+1));//Calendar.MONTH获取的范围是0~11
//  System.out.println("日:"+calendar.get(Calendar.DAY_OF_MONTH));
//  System.out.println("时:"+calendar.get(Calendar.HOUR_OF_DAY));
//  System.out.println("分:"+calendar.get(Calendar.MINUTE));
//  System.out.println("秒:"+calendar.get(Calendar.SECOND));
// 
//  calendar.add(calendar.MONTH, 2);//calendar基础上添加2个月
//  System.out.println(calendar.getTime());//calendar.getTime()是将Calendar转换为Date
// }

你可能感兴趣的:(calendar)