โ๏ธ ๊น์ํ์ ์ค์ ์๋ฐ - ์ค๊ธ 1ํธ ์ ๋ฃ๊ณ ์์ฑํ๋ ๋ณต์ต ๋ธ๋ก๊ทธ ์ ๋๋ค.
0. ๋ฐฐ๊ฒฝ
ํ๋ก๊ทธ๋จ์ ๊ฐ๋ฐํ๋ค๋ณด๋ฉด ๐
๋ ์ง์ ๐ฐ๏ธ ์๊ฐ ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ๊ตฌํํด์ผํ ์ผ์ด ์์ฃผ ์๊ธด๋ค.
์๋ฅผ ๋ค์ด์
๐ฐ ์ ์ฐ ํ๋ก๊ทธ๋จ์ ๊ฐ๋ฐํ ๊ฒฝ์ฐ ํน์ ์์ ์ฌ์ด์ ์ ์ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์์ผ ํ๊ณ
๐์ผ๋ฐ์ ์ธ ๋ฐ์ดํฐ ์กฐํ์์๋ ์ฌ์ฉ์๊ฐ ์ํ๋ ๋ ์ง๋ฅผ ์ง์ ํด์ ๊ฒ์ํ ์ ์์ด์ผ ํ๋ค.
์๋ฐ์๋ ๋ ์ง์ ์๊ฐ ๊ด๋ จ๋ ์ฌ๋ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์กด์ฌํ๋๋ฐ, ์ด๋ฒ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ํด์ ์์๋ณด์
1. ๋ ์ง์ ์๊ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ์ํ ์ด์
๐ฌ "๊ตณ์ด ๋ ์ง์ ์๊ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํ์ํ ๊น ?"
๐ฌ "๊ทธ๋ฅ ๋ด๊ฐ ํ๋ํ๋ ๊ณ์ฐํ๋ฉด ๋์ง ์์๊น ?" ๋ผ๊ณ ์๊ฐํ ์ ์๋ค.
ํ์ง๋ง, ๋ ์ง์ ์๊ฐ์ ๊ทธ๋ฅ ๊ณ์ฐํ๊ธฐ์ ๊ณ ๋ คํด์ผํ ์์๋ค์ด ๋ง๋ค.
1. ๐ ์ค๋
์ง๊ตฌ๊ฐ ํ์์ ํ ๋ฐํด ๋๋๋ฐ ํ๊ท 365.425์ผ์ด ๊ฑธ๋ฆฐ๋ค.
์ ํํ 365์ผ์ด ์๋๊ธฐ ๋๋ฌธ์ ๋๋จธ์ง 0.425์ผ์ ๋ํด์ ์ฝ 4๋ ๋ง๋ค ํ๋ฃจ๋ฅผ ์ถ๊ฐํ๋ ์ค๋ ์ ์ฌ์ฉํ๋ค
2. โ๏ธ ์ผ๊ด ์ ์ฝ ์๊ฐ
์ธ๋จธํ์์ด๋ผ๊ณ ๋ ํ๋ค.
๊ตญ๊ฐ๋ ์ง์ญ์ ๋ค๋ผ ์ ์ฉ ์ฌ๋ถ์ ์์ ๋ฐ ์ข ๋ฃ ๋ ์ง๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๋๋ผ๋ณ๋ก 1์๊ฐ ์ค์ฐจ๊ฐ ๋ฐ์ํ ์ ์๋ค.
3. ๐ฐ๏ธ ํ์์กด
๋๋ผ๋ง๋ค ๋ค์ํ ํ์์กด์ผ๋ก ๋๋์ด์ ธ ์๋ค.
๊ฐ ํ์์กด์ UTC ๋ก๋ถํฐ์ ์๊ฐ ์ฐจ์ด๋ก ์ ์๋๋ค.
์ด๋ฐ ๋ ์ง์ ์๊ฐ ๋ค์ํ ๊ฒ๋ค์ ๋ชจ๋ ๋ฐ์ํ๊ธฐ์ ํผ์ ๊ฐ๋ฐํด์๋ ์ด๋ ต๋ค
→ ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ ์ค๊ณ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
2. ์๋ฐ ๋ ์ง์ ์๊ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์ค๋ผํด์ ์๋ฐ document ์ ๋ ์ง์ ์๊ฐ ๊ด๋ จ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ํด์ ์ ๋ฆฌ๋ ํ๊ฐ ์๋ค
๊ฐ๋จํ๊ฒ ์ค๋ช ํ์๋ฉด ๋ค์๊ณผ ๊ฐ๋ค
๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ช | ์ค๋ช | ํ์ |
LocalDate | ๋ ์ง๋ง ํํํ ๋ ์ฌ์ฉ | 2013-12-21 |
LocalTime | ์๊ฐ๋ง ํํํ ๋ ์ฌ์ฉ | 08:20:30.213 |
LocalDateTime | ๋ ์ง + ์๊ฐ์ ํํํ ๋ ์ฌ์ฉ | 2013-12-21T08:20:30.213 |
ZonedDateTime | ์๊ฐ๋๋ฅผ ๊ณ ๋ คํ ๋ ์ง์ ์๊ฐ์ ํํ (+ ํ์์กด ํฌํจ) | 2013-11-21T08:20:30.213+9:00[Asia/Seoul] |
OffsetDateTime | ์๊ฐ๋๋ฅผ ๊ณ ๋ คํ ๋ ์ง์ ์๊ฐ์ ํํ (+ ํ์์กด ๋ฏธํฌํจ) | 2013-11-21T08:20:30.213+9:00 |
Instance | UTC๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๋ ์๊ฐ์ ํ ์ง์ | |
Period | ๋ ๋ ์ง ์ฌ์ด์ ๊ฐ๊ฒฉ (๋ / ์ / ์ผ) | |
Duration | ๋ ์๊ฐ ์ฌ์ด์ ๊ฐ๊ฒฉ (์ / ๋ถ / ์ด) |
3. LocalDate, LocalTime, LocalDateTime
๐ก ์๊ฐ๋๋ฅผ ๊ณ ๋ คํ์ง ์๊ณ , ๋ ์ง์ ์๊ฐ์ ๊ณ์ฐํ๋ ๊ฒฝ์ฐ ์ฌ์ฉ
LocalDate, LocalTime, LocalDateTime ๋ชจ๋ ์์ Local ์ด ๋ถ๋๋ค.
๐ โ๏ธ์ด๋ ์ธ๊ณ ์๊ฐ๋๋ฅผ ๊ณ ๋ คํ์ง ์๋๋ค๋ ์๋ฏธ๋ก, ํ์์กด์ด ์ ์ฉ๋์ง ์๋๋ค.
LocalDate : ๋ ์ง
LocalDate now = LocalDate.now();
LocalDate ofDate = LocalDate.of(2025, 7, 7);
LocalDate ofDatePlus10 = ofDate.plusDays(10);
System.out.println("now = " + now);
System.out.println("ofDate = " + ofDate);
System.out.println("ofDatePlus10 = " + ofDatePlus10);
now = 2025-07-07
ofDate = 2025-07-07
ofDatePlus10 = 2025-07-17
- now() : ํ์ฌ ๋ ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก LocalDate ๋ฅผ ์์ฑํ๋ค
- of(๋ , ์, ์ผ) : ํน์ ๋ ์ง๋ฅผ ๊ธฐ์ค์ผ๋ก LocalDate ๋ฅผ ์์ฑํ๋ค.
- plusDays(์ผ) : ์ผ์ ๋ํ๋ค
LocalTime : ์๊ฐ
LocalTime now = LocalTime.now();
LocalTime ofTime = LocalTime.of(12, 0, 0);
LocalTime ofTimePlusHour = ofTime.plusHours(10);
System.out.println("now = " + now);
System.out.println("ofTime = " + ofTime);
System.out.println("ofTimePlusHour = " + ofTimePlusHour);
now = 17:14:28.122669
ofTime = 12:00
ofTimePlusHour = 22:00
- now() : ํ์ฌ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก LocalTime ๋ฅผ ์์ฑํ๋ค
- of(์๊ฐ, ๋ถ, ์ด) : ํน์ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก LocalTime ๋ฅผ ์์ฑํ๋ค.
- plusHours(์๊ฐ) : ์๊ฐ์ ๋ํ๋ค
LocalDateTime : ๋ ์ง + ์๊ฐ
LocalDateTime now = LocalDateTime.now();
LocalDateTime ofDateTime = LocalDateTime.of(2025, 7, 7, 12, 0, 0);
LocalDateTime ofDateTimePlusDays = ofDateTime.plusDays(10);
LocalDateTime ofDateTimePlusHours = ofDateTime.plusHours(10);
System.out.println("now = " + now);
System.out.println("ofDateTime = " + ofDateTime);
System.out.println("ofDateTimePlusDays = " + ofDateTimePlusDays);
System.out.println("ofDateTimePlusHours = " + ofDateTimePlusHours);
now = 2025-07-07T17:17:33.380426
ofDateTime = 2025-07-07T12:00
ofDateTimePlusDays = 2025-07-17T12:00
ofDateTimePlusHours = 2025-07-07T22:00
- now() : ํ์ฌ ๋ ์ง, ์๊ฐ์ ๊ธฐ์ค์ผ๋ก LocalDateTime ๋ฅผ ์์ฑํ๋ค
- of(๋ , ์, ์ผ, ์๊ฐ, ๋ถ, ์ด) : ํน์ ๋ ์ง, ์๊ฐ ์ ๊ธฐ์ค์ผ๋ก LocalDateTime ๋ฅผ ์์ฑํ๋ค.
- plusHours(์๊ฐ) : ์๊ฐ์ ๋ํ๋ค
- plusDays(์ผ) : ์ผ์ ๋ํ๋ค
→ LocalDateTime ์ ์๊ฐ๊ณผ ๋ ์ง๋ฅผ ๋ชจ๋ ๊ฐ์ง๊ธฐ ๋๋ฌธ์ plusHours, plusDays ๋ฅผ ์ฌ์ฉํ ์ ์๋ค
4. ZonedDateTime, OffsetDateTime
๐ก ํ์์กด์ ๊ณ ๋ คํ ๋ ์ง์ ์๊ฐ์ ์ฌ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ
ZonedDateTime์ ๋ค๋ฅธ ๋๋ผ์์ ํ์์กด์ ๊ณ ๋ คํ๋ค.
์๋ฐ์์ ํ์์กด์ ZoneId ๋ก ์ ๊ณต๋๋ค.
ZoneId
for (String availableZoneId : ZoneId.getAvailableZoneIds()) {
System.out.println(availableZoneId);
}
System.out.println("ZoneId.systemDefault = " + ZoneId.systemDefault());
System.out.println("ZoneId.of = " + ZoneId.of("Asia/Seoul"));
- ZoneId.systemDefault() : ์์คํ ์ด ์ฌ์ฉํ๋ ๊ธฐ๋ณธ ZoneId ๋ฅผ ๋ฐํํ๋ค
- ZoneId.of() : ์ ๋ ฅ๋ ํ์์กด์ ํด๋นํ๋ ZoneId ๋ฅผ ๋ฐํํ๋ค
- ZoneId.getAvailableZoneIds() : ์ฌ์ฉ๊ฐ๋ฅํ ๋ชจ๋ ZoneId ๋ฅผ ๋ฐํํ๋ค
- DST (์๋จธ ํ์) ์ ๋ณด๋ฅผ ํฌํจํ๋ค.
ZonedDateTime
public final class ZonedDateTime implements Temporal, ChronoZonedDateTime<LocalDate>, Serializable {
private final LocalDateTime dateTime;
private final ZoneOffset offset;
private final ZoneId zone;
}
- ZonedDateTime ์ ๋ด๋ถ์ LocalDateTime, ZoneOffset, ZoneId ๊ฐ ์๋ค
- ๋ ์ง์ ์๊ฐ์ ๋ํ๋ด๋ LocalDateTime ์ ์๊ฐ๋๋ฅผ ํํํ๋ ํ์์กด์ด ํฌํจ๋๋ค.
ZonedDateTime zdt1 = ZonedDateTime.now();
System.out.println("zdt1 = " + zdt1);
ZonedDateTime zdt2 = ZonedDateTime.of(2030, 1, 1, 13, 30, 50, 0, ZoneId.of("Asia/Seoul"));
System.out.println("zdt2 = " + zdt2);
ZonedDateTime utcZdt = zdt2.withZoneSameInstant(ZoneId.of("UTC"));
System.out.println("utcZdt = " + utcZdt);
zdt1 = 2025-07-07T17:37:36.873016+09:00[Asia/Seoul]
zdt2 = 2030-01-01T13:30:50+09:00[Asia/Seoul]
utcZdt = 2030-01-01T04:30:50Z[UTC]
- now() : ํ์ฌ ๋ ์ง์ ์๊ฐ์ผ๋ก ์์ฑ, ํ์์กด์ ์์คํ ์๊ฐ์ผ๋ก ๋ค์ด๊ฐ๋ค
- of() : ํน์ ๋ ์ง์ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ์์ฑ, ZoneId ๋ฅผ ์ง์ ํ ์ ์๋ค
- withZoneSameInstance(ZoneId) : ํด๋น ์๊ฐ์ ํ์์กด์ ๋ณ๊ฒฝํ ์ ์๋ค
OffsetDateTime
public final class OffsetDateTime implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable {
private final LocalDateTime dateTime;
private final ZoneOffset offset;
}
- LocalDateTime ์ ZoneOffset ๋ง ์ถ๊ฐ๋์ด ์๋ค
- ZoneId ๊ฐ ์๊ธฐ ๋๋ฌธ์ ํ์์กด์ ๊ณ์ฐํ ์ ์๋ค
ZoneOffset
UTC ๊ธฐ์ค์ ๊ณ ์ ๋ ์๊ฐ ์ฐจ์ด๋ฅผ ๋ํ๋ธ๋ค ex) "+09:00", "-05:00" ๋ฑ
์๋จธํ์ (DST) ๋ฅผ ๊ณ ๋ คํ์ง ์๋๋ค
OffsetDateTime nowOdt = OffsetDateTime.now();
System.out.println("nowOdt = " + nowOdt);
OffsetDateTime odt = OffsetDateTime.of(LocalDateTime.of(2030, 1, 1, 13, 30, 50), ZoneOffset.of("+01:00"));
System.out.println("odt = " + odt);
nowOdt = 2025-07-07T17:55:54.615875+09:00
odt = 2030-01-01T13:30:50+01:00
- now() : ํ์ฌ ๋ ์ง์ ์๊ฐ์ผ๋ก ์์ฑ
- of() : ํน์ ๋ ์ง์ ์๊ฐ์ ๊ธฐ์ค์ผ๋ก ์์ฑ, Zoneoffset ์ ์ง์ ํ ์ ์๋ค
5. Instant
๐ก ์๊ฐ๋ ๋ณํ ์์ด ์๊ฐ ๊ณ์ฐ์ด ํ์ํ ๋
public final class Instant implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable {
private final long seconds;
private final int nanos;
}
- ๋ด๋ถ์ ์ผ๋ก ์ด์ ๋๋ ธ์ด๋ง ๊ฐ์ง๊ณ ์๋ค
- 1970๋ 1์ ์ผ 0์ 0๋ถ 0์ด๋ฅผ ๊ธฐ์ค์ผ๋ก ๊ฒฝ๊ณผํ ์๊ฐ์ ๊ฐ์ง๋ค
- UTC ๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๊ธฐ ๋๋ฌธ์ ์๊ฐ๋์ ์ํฅ์ ์ฃผ์ง ์๋๋ค
- ์ฌ๋์ด ์ฝ๊ณ ์ดํดํ๊ธฐ์๋ ์ง๊ด์ ์ด์ง ์๋ค
์ฌ์ฉ
- ์ ์ธ๊ณ์ ์ธ ์๊ฐ ๊ธฐ์ค์ด ํ์ํ ๋
- ์๊ฐ๋ ๋ณํ ์์ด ์๊ฐ ๊ณ์ฐ์ด ํ์ํ ๋
- ๋ฐ์ดํฐ ์ ์ฅ ๋ฐ ๊ตํ
์ ์ฌ์ฉ๋๋ค.
Instant now = Instant.now(); // UTC ๊ธฐ์ค
System.out.println("now = " + now);
now = 2025-07-07T08:59:50.508822Z
์ด๊ฐ ๋ค์ด์์ง๋ง ์ถ๋ ฅํ ๋๋ ๋ ์ง ํ์์ ๋ง์ถฐ์ ์ถ๋ ฅ๋๋๋ฐ
@Override
public String toString() {
return DateTimeFormatter.ISO_INSTANT.format(this);
}
Instant ํด๋์ค ๋ด๋ถ์์ toString() ์ ์ค๋ฒ๋ผ์ด๋ฉ ํ๊ธฐ ๋๋ฌธ์ด๋ค
6. Duration, Period
๐ก ๋ ๋ ์ง ์ฌ์ด์ ๊ฐ๊ฒฉ์ด๋ ์๊ฐ ์ฌ์ด์ ๊ฐ๊ฒฉ์ ๋ํ๋ผ ๋
Period ๋ ๋ ๋ ์ง ์ฌ์ด์ ๊ฐ๊ฒฉ์ ๋ / ์ / ์ผ ๋จ์๋ก ๋ํ๋ธ๋ค
// ์์ฑ
Period period = Period.ofDays(10);
System.out.println("period = " + period);
// ๊ณ์ฐ์ ์ฌ์ฉ
LocalDate plusDate = LocalDate.of(2030, 1, 1).plus(period);
System.out.println("plusDate = " + plusDate);
// ๊ธฐ๊ฐ ์ฐจ์ด
Period between = Period.between(LocalDate.of(2023, 1, 1), LocalDate.of(2023, 4, 2));
System.out.println("๊ธฐ๊ฐ: " + between.getMonths() + "๊ฐ์ " + between.getDays() + "์ผ");
- ofXXX() : ํน์ ๊ธฐ๊ฐ์ ์ง์ ํด์ Period ๋ฅผ ์์ฑ
- plus(Period period): ํน์ ๋ ์ง์ ๊ธฐ๊ฐ์ ๋ํ ์ ์๋ค
- between(startDate, endDate) : ํน์ ๋ ์ง์ ์ฐจ์ด๋ฅผ ๊ตฌํ ์ ์๋ค
Duration ์ ๋ ์๊ฐ ์ฌ์ด์ ๊ฐ๊ฒฉ์ ์ / ๋ถ / ์ด ๋จ์๋ก ๋ํ๋ธ๋ค
// ์์ฑ
Duration duration = Duration.ofMinutes(30);
System.out.println("duration = " + duration);
// ๊ณ์ฐ
LocalTime plusTime = LocalTime.of(1, 0).plus(duration);
System.out.println("๋ํ ์๊ฐ: " + plusTime);
// ์๊ฐ ์ฐจ์ด
Duration between = Duration.between(LocalTime.of(9, 0), LocalTime.of(10, 0));
System.out.println("์ฐจ์ด : " + between.getSeconds() + "์ด");
System.out.println("๊ทผ๋ฌด ์๊ฐ: " + between.toHours() + "์๊ฐ " + between.toMinutesPart() + "๋ถ");
- ofXXX() : ํน์ ์๊ฐ์ ์ง์ ํด์ Period ์์ฑ
- plus() : LocalTime ์ Period ๋ฅผ ๋ํ ์ ์๋ค
- between() : LocalTime๊ฐ์ ์ฐจ๋ฆฌ๋ฅผ ๊ตฌํ ์ ์๋ค
- toMinutes() : ์ ์ฒด ๋ถ
- toMinutesPart() : ์๊ฐ์ ๋นผ๊ณ ๋ ํ์ ๋ถ
7. ๋ ์ง์ ์๊ฐ ํต์ฌ ์ธํฐํ์ด์ค
๋ ์ง์ ์๊ฐ์ ํน์ ์์ ๊ณผ ๊ฐ๊ฒฉ์ผ๋ก ๋๋ ์ ์๋ค.
- ํน์ ์์ : ๋ด ์์ผ์ 2์ 7์ผ์ด์ผ
- ์๊ฐ์ ๊ฐ๊ฒฉ : ๋ด ์์ผ๊น์ง 3์ผ ๋จ์์ด
ํน์ ์์ ์ ๋ํ๋ด๋ ํด๋์ค๋ ์์์ ์ดํด๋ดค๋
- LocalDateTime
- ZonedDateTime
- Instance
๊ฐ ์๊ณ , ๊ฐ ํด๋์ค๋ Temporal ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๊ณ , Temporal ์ธํฐํ์ด์ค๋ TemporalAccessor ๋ฅผ ์์๋ฐ๋๋ค
์๊ฐ์ ๊ฐ๊ฒฉ์ ๋ํ๋ด๋ ํด๋์ค๋
- Period
- Duration
์ด ์๊ณ , ๊ฐ ํด๋์ค๋ TemporalAmount ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๋ค.
8. ์๊ฐ์ ๋จ์์ ์๊ฐ ํ๋
์๊ฐ์ ๋จ์ - ChronoUnit
- ์์ ๊ฐ์ด ์๊ฐ ๋จ์ / ๋ ์ง ๋จ์ / ๊ธฐํ ๋จ์ ๋ณ๋ก ๋ค์ํ ChronoUnit ์ ๊ฐ์ง๋ค.
- TemporalUnit ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๋ค
LocalTime lt1 = LocalTime.of(1, 10, 0);
LocalTime lt2 = LocalTime.of(1, 20, 0);
long secondsBetween = ChronoUnit.SECONDS.between(lt1, lt2);
System.out.println("secondsBetween = " + secondsBetween);
- ๋ ๋ ์ง / ์๊ฐ ์ฐจ์ด๋ฅผ ์ํ๋ ๋จ์๋ก ์ฝ๊ฒ ๊ณ์ฐํ ์ ์๋ค
์๊ฐ ํ๋- ChronoField
- ๋ ์ง์ ์๊ฐ์ ํน์ ๋ถ๋ถ์ ๋ํ๋ด๋ ๋ฐ ์ฌ์ฉ๋๋ ์ด๊ฑฐํ
- ๋ ์ง์ ์๊ฐ์ ๊ฐ ํ๋ ์ค์์ ์ํ๋ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ ์ ์๋ค
LocalDateTime dt = LocalDateTime.of(2030, 1, 1, 13, 30, 59);
System.out.println("YEAR = " + dt.get(ChronoField.YEAR));
System.out.println("YEAR = " + dt.getYear());
LocalDateTime changedDt1 = dt.with(ChronoField.YEAR, 2020);
LocalDateTime changedDt2 = dt.withYear(2020);
LocalDateTime with = dt.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
9. ๋ฌธ์์ด ํ์ฑ๊ณผ ํฌ๋งทํ
ํฌ๋งทํ : ๋ ์ง์ ์๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ํ๋ ํฌ๋งท์ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝ (Date→String)
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy๋
MM์ dd์ผ");
String formattedDate = date.format(formatter);
System.out.println("๋ ์ง์ ์๊ฐ ํฌ๋งทํ
= " + formattedDate);
ํ์ฑ : ๋ฌธ์์ด์ ๋ ์ง์ ์๊ฐ ๋ฐ์ดํฐ๋ก ๋ณ๊ฒฝ (String→ Date)
String input = "2030๋
01์ 01์ผ";
LocalDate parseDate = LocalDate.parse(input, formatter);
System.out.println("๋ฌธ์์ด ํ์ฑ ๋ ์ง์ ์๊ฐ: " + parseDate);
'๐ฑ ์ธํ๋ฐ > โ๏ธ ๊น์ํ์ ์ค์ ์๋ฐ - ์ค๊ธ 1ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ Object ํด๋์ค (0) | 2025.09.01 |
---|---|
์๋ฐ ๋ํผ, Class ์ด์ ๋ฆฌ (0) | 2025.07.19 |
์๋ฐ ์์ธ์ฒ๋ฆฌ ์ด์ ๋ฆฌ (1) | 2025.07.11 |
์๋ฐ ์ด๊ฑฐํ ENUM ์ด์ ๋ฆฌ (2) | 2025.07.10 |
์๋ฐ ์ค์ฒฉ ํด๋์ค์ ๋ด๋ถ ํด๋์ค (3) | 2025.07.09 |