Java Date - ZoneID 날짜와 시간 다루기
ZonedDateTime 클래스는 Asia/Seoul 표기와 같은 타임존과 일광 절약 시간제에 대한 정보 그리고 UTC+9:00 오프셋 정보를 모두 포함하고 있다.
타임존 목록
- UTC +0:00
- US/Arizona +07:00
- Asia/Soul +09:00
- Europe/Paris +01:00
ZoneID 클래스
- 타임존 조회 방법은 자바 ZonedID 클래스로 제공함
getAvailableZoneIds - 타임존 목록 조회하기
for (String availableZoneId : ZoneId.getAvailableZoneIds()) {
System.out.println("ZoneID: " + availableZoneId);
}
...
ZoneID: Asia/Kathmandu
ZoneID: Asia/Seoul
ZoneID: Australia/Sydney
ZoneID: America/Lima
...
모두 나열하기 어려울 정도로 많은 타임존이 있다.
getRules - 타임존에 대한 정보 출력
for (String availableZoneId : ZoneId.getAvailableZoneIds()) {
ZoneId zoneId = ZoneId.of(availableZoneId);
System.out.println(zoneId + " @@ " + zoneId.getRules());
}
...
Africa/Kinshasa @@ ZoneRules[currentStandardOffset=+01:00]
Asia/Kathmandu @@ ZoneRules[currentStandardOffset=+05:45]
Asia/Seoul @@ ZoneRules[currentStandardOffset=+09:00]
Australia/Sydney @@ ZoneRules[currentStandardOffset=+10:00]
America/Lima @@ ZoneRules[currentStandardOffset=-05:00]
...
타임존 객체의 여러 정보를 제공하고 있다.
systemDefault - 나의 운영체제로부터 타임존 조회하기
ZoneId zone = ZoneId.systemDefault();
System.out.println("My Time Zone: " + zone);
My Time Zone: Asia/Seoul
of - 문자열로 객체에 타임존에 대한 정보 담기
ZoneId zone = ZoneId.of("Asia/Seoul");
System.out.println("Get Time Zone: " + zone);
Get Time Zone: Asia/Seoul
객체에는 타임존은 시간과 일광 절약 시간 적용여부, UTC와 오프셋 정보를 담고 있다.