Skip to content

Timzone 관련 이슈 해결 공유 #124

@shon5544

Description

@shon5544

Description

이슈 해결 공유

ec2의 default timezone이 UTC로 잡혀있었기 때문에 LocalDateTime(or LocalDate or LocalTime).now를 사용하는 모든 로직이 이상하게 동작했습니다.

한국 시간보다 대략 9시간 정도 느린데, 이런 새벽에 시도하면 한국날짜는 08.16일인데 ec2에서 기록, 탐색하는 건 08.15의 날짜를 사용하는 해괴망측한 일이 일어나버립니다,,

이런 일이 벌어진 이유는 Local~이 붙는 시간 객체(LocalDateTIme, LocalDate, LocalTime)는 디바이스의 시간에 영향을 받기 때문에, 디바이스의 시간과 현실 유저들의 시간이 다르다면 유저가 기대하는 기록 값(기록 시간)과 실제 기록 값(기록 시간)이 달라지기 때문입니다.

제가 사용한 해결책은 두 개입니다.

  1. Spring Boot 자체의 Timezone 설정
// 생략
@SpringBootApplication
public class YourweatherApplication {

    @PostConstruct
    public void started() {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
    }
    // 생략
}

실패: 어떤 건 되고 어떤 건 안 되고.. 이유는 정말 모르겠으나 같은 날에 2개이상 생길 수 없는 weather 객체가 두 개 생기고...
정말 이상한 오류가 발견되어 이것만으로는 부족하다고 판단했습니다.

  1. ec2의 timezone을 직접 수정
sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime

이런 식으로 심볼릭 링크를 만들어주면 ec2의 timezone을 변경해줄 수 있습니다.

  1. 결과
    image
    아무리 많이 요청해도 정확히 원하는 결과를 던져줌.

Metadata

Metadata

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions