Date
클래스의 문제점 (with Calendar
, SimpleDateFormat
)java.time
패키지 내부에 존재한다.Instant
를 사용한다.LocalDate
, LocalTime
, LocalDateTime
를 사용한다.Duration
(기계용 시간 기반)과 Period
(인류용 날짜 기반)을 사용할 수 있다.DateTimeFormatter
를 사용한다.Instant
EPOCK(1970년 1월 1일 0시 0분 0초)부터 현재까지의 타임스탬프를 표현한다.
ZonedDateTime atZone(ZoneId)
LocalDateTime
인류용 시간(우리가 흔히 사용하는 년,월,일,시,분,초 등)을 표현한다.
ZonedDateTime.now(ZoneId.of("Asia/Seoul")
now()
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)
DateTimeFormat
LocalDateTime
과 문자열간의 변환을 지원한다.
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', 백기선