1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public class Test { public static void main(String[] args) { System.out.println("----------使用Calendar--------------------"); Calendar cal = Calendar.getInstance(); System.out.println("年"+cal.get(Calendar.YEAR)); System.out.println("月"+(cal.get(Calendar.MONTH)+1)); System.out.println("日"+cal.get(Calendar.DATE)); System.out.println(cal.get(Calendar.HOUR)); System.out.println("时"+cal.get(Calendar.HOUR_OF_DAY)); System.out.println("分"+cal.get(Calendar.MINUTE)); System.out.println("秒"+cal.get(Calendar.SECOND));
System.out.println("--------------使用java8的LocalDateTime----------------"); LocalDateTime local = LocalDateTime.now(); System.out.println("年"+local.getYear()); System.out.println(local.getMonth().name()); System.out.println("月"+local.getMonthValue()); System.out.println("日"+local.getDayOfMonth()); System.out.println("时"+local.getHour()); System.out.println("分"+local.getMinute()); System.out.println("秒"+local.getSecond()); } }
|