: Java에서 제공하는 Date, Time API는 부족한 기능 지원을 포함한 여러가지 문제점을 가지고 있었다. JDK에서 이런 문제점들을 해결하고 더 좋고 직관적인 API들을 제공하기 위해 새롭게 재디자인한 Date, Time API를 Java SE 8부터 제공한다.
LocalDateTime 클래스를 이용해서 현재 시간 time 객체 만드는 방법
LocalDateTime timePoint = LocalDateTime.now(); // 현재의 날짜와 시간
원하는 시간으로 time 객체 생성하는 방법
// 2012년 12월 12일의 시간에 대한 정보를 가지는 LocalDate 객체를 만드는 방법
LocalDate ld1 = LocalDate.of(2012, Month.DECEMBER, 12);
// 17시 18분에 대한 LocalTime객체를 구한다.
LocalTime lt1 = LocalTime.of(17, 18);
// 10시 15분 30초라는 문자열에 대한 LocalTime 객체를 구한다.
LocalTime lt2 = LocalTime.parse("10:15:30"); // From a String
현재의 날짜와 시간정보를 getter 메소드를 이용하여 구하는 방법
LocalDate theDate = timePoint.toLocalDate();
// 연월일까지만 출력한다.
System.out.println(theDate);
Month month = timePoint.getMonth();
int day = timePoint.getDayOfMonth();
int hour = timePoint.getHour();
int minute = timePoint.getMinute();
int second = timePoint.getSecond();
// 달을 숫자로 출력한다.
System.out.println(month.getValue() + "/" + day + " " + hour + ":" + minute + ":" + second);