dateTime์ โzโ๋ฅผ ๋ถ์ฌ๋ฌ๋ผ๋ ํ๋ก ํธ์ ์์ฒญ์ด ์์์ต๋๋ค.
LocalDateTime : "2022-02-23T12:51:17"
ZonedDateTime : "2022-02-23T12:51:17.233Z"
์์ ์์์ฒ๋ผ ๋ฐ์ดํฐ ํ์์ โzโ๋ก DateTime์ zone์ ํํํด์ค๋๋ค. (UTC๊ธฐ์ค์ผ๋!)
๋ชจ๋ LocalDateTime ๋ณ์๋ค์ ZonedDateTime์ผ๋ก ๋ณ๊ฒฝํ๊ณ DB์ ์นผ๋ผ๋ ZonedDateTime์ผ๋ก ๋ณ๊ฒฝํ์์ต๋๋ค.
ํ๋ก ํธ์ ๋ฐฑ ์ฌ์ด์ ํต์ ์ ๋ชจ๋ UTC ๊ธฐ์ค์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค.
UTC์ KST๋ +9์๊ฐ์ ์ฐจ์ด๊ฐ ์๊ธฐ ๋๋ฌธ์ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์กฐํํ ๋ ์ ์ํด์ผ ํฉ๋๋ค.
๋๋ฌธ์ ์๊ฐ ๊ธฐ์ค์ผ๋ก ์กฐํ๋ฅผ ํ ๋ UTC โ KST โUTC๋ก ๊ณผ์ ์ ๊ฑฐ์ณ ์กฐํํ์์ต๋๋ค.
๋ฒ๊ฑฐ๋กญ๊ฒ ๋ณด์ผ ์ ์์ง๋ง ํต์ ์ UTC ๊ธฐ์ค์ผ๋ก ํ ๋ ์๋น์ค ํ์ฅ์ฑ์ ๊ฐ์ ธ๊ฐ ์ ์์ต๋๋ค.
final ZonedDateTime currentTimeOfKorea = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
final ZonedDateTime todayStart = ZonedDateTime.of(
currentTimeOfKorea.getYear(),
currentTimeOfKorea.getMonthValue(),
currentTimeOfKorea.getDayOfMonth(),
0, 0, 0, 0, ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneOffset.UTC);
๋์์ด ๋๋ ์ฌ์ดํธ
ZonedDateTime (Java Platform SE 8 )
static ZonedDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone) Obtains an instance of ZonedDateTime from a year, month, day, hour, minute, second, nanosecond and time-zone.
docs.oracle.com
[Java8 Time API] ZonedDateTime ์ฌ์ฉ๋ฒ
Engineering Blog by Dale Seo
www.daleseo.com
'๊ฐ๋ฐ > Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์คํ๋ง ์น ๊ฐ๋ฐ ๋ฐฉ์ (static / MVC / API) (0) | 2022.03.03 |
---|---|
Spring ํ๋ก์ ํธ ์์ฑ (Gradle) (0) | 2022.03.03 |
Spring ํตํฉ ํ ์คํธ - JUnit5 (0) | 2022.02.21 |
GraphQL (spring) (0) | 2021.12.18 |
JavaScript ์์ ์ฝ๋ (axios/restAPI/HackerRank) (0) | 2021.11.18 |