- /** 单独输出年月日时分秒等 */
- Calendar c = Calendar.getInstance();
- System.out.println("年: " + c.get(Calendar.YEAR));
- // 月份从0开始,加1校正
- System.out.println("月: " + (c.get(Calendar.MONTH) + 1) + "");
- System.out.println("日: " + c.get(Calendar.DAY_OF_MONTH));
- System.out.println("时: " + c.get(Calendar.HOUR_OF_DAY));
- System.out.println("分: " + c.get(Calendar.MINUTE));
- System.out.println("秒: " + c.get(Calendar.SECOND));
- System.out.println("当前时间毫秒数:" + c.getTimeInMillis());
- System.out.println("当前时间: " + c.getTime());