Back-End/Spring Boot
Spring Boot | LocalDateTime timezone 세팅하기
개발자티포
2023. 8. 29. 09:36
728x90
반응형
기본적으로 LocalDateTime에는 timezone이 없기 때문에 따로 세팅을 해주어야한다.
먼저 now를 생성할 때 다음과 같이 UTC 시간을 준다.
LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC);
그 다음 timezone을 세팅할 때 다음과 같이 해준다.
now..atZone(TimeZone.getDefault().toZoneId())
.format(DateTimeFormatter.RFC_1123_DATE_TIME)
어떤 형식으로 보여줄 지는 다음 사이트를 참고하면 된다.
DateTimeFormatter (Java Platform SE 8 ) (oracle.com)
DateTimeFormatter (Java Platform SE 8 )
Parses the text using this formatter, without resolving the result, intended for advanced use cases. Parsing is implemented as a two-phase operation. First, the text is parsed using the layout defined by the formatter, producing a Map of field to value, a
docs.oracle.com
728x90
반응형