Skip to content

Instantly share code, notes, and snippets.

@hatemogi
Created March 8, 2021 08:25
Show Gist options
  • Save hatemogi/7e3bd9017ec0017352a3209893600c05 to your computer and use it in GitHub Desktop.
Save hatemogi/7e3bd9017ec0017352a3209893600c05 to your computer and use it in GitHub Desktop.
java.time.Instant 류의 차이점

Instant, LocalDateTime, OffsetDateTime, ZonedDateTime

  • Instant는 UTC기준 유닉스 타임스탬프. 초를 나타내는 long, nano초를 나타내는 int로 구성됨.
  • LocalDateTime은, 시간대는 없이, 시간 자체만 nano초단위까지 표현.
  • OffsetDateTime은, 시간대 정보를 UTC기준 오프셋(ZoneOffset)으로 관리하는 시간. 예) UTC+09
  • ZonedDateTime은, 시간대 정보를 ZoneId로 관리. 예) Asia/Tokyo

각각의 차이

  • LocalDateTime vs. OffsetDateTime|ZonedDateTime => 시간대 정보 포함 여부
  • OffsetDateTime vs ZonedDateTime => 시간대 정보를 오프셋으로 관리할지 지역으로 관리할지의 차이.
  • 특정 도시가 경도가 UTC에서 9시간 떨어져 있다고 하더라도, 섬머타임 실시여부에 따라서 실제 시간의 차이가 있을 수 있기 때문에, OffsetDateTime과 ZonedDateTime 사이에 차이가 생길 수도 있다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment