Date 클래스의 문제점 (with Calendar, SimpleDateFormat )java.time 패키지 내부에 존재한다.Instant를 사용한다.LocalDate, LocalTime, LocalDateTime를 사용한다.Duration(기계용 시간 기반)과 Period(인류용 날짜 기반)을 사용할 수 있다.DateTimeFormatter를 사용한다.Date 관련 클래스들과 서로 변환이 가능하다.InstantEPOCK(1970년 1월 1일 0시 0분 0초)부터 현재까지의 타임스탬프를 표현한다.
ZonedDateTime atZone(ZoneId)LocalDateTime인류용 시간(우리가 흔히 사용하는 년,월,일,시,분,초 등)을 표현한다.
now()ZonedDateTime.now(ZoneId.of("Asia/Seoul"))of(1999, Month.JULY, 8, 0, 0, 0);Period인류용 시간에서 날짜를 기반으로 기간을 계산한다.
Period.between(LocalDate before, LocalDate after)localDate.until(LocalDate after)Duration기계용 시간을 기반으로 기간을 계산한다.
Duration.between(Instant before, Instant after)DateTimeFormatLocalDateTime과 문자열간의 변환을 지원한다.
ofPattern(String)LocalDateTime 출력 : localDateTime.format(DateTimeFormatter)LocalDateTime로 변환 : LocalDate.parse(String, DateTimeFormatter)TimeZone before Java 8 → ZoneId since Java 8
ZoneId.SystemDefault()ZoneId.of("Asia/Seoul")Reference
인프런 - '더 자바, Java 8', 백기선