Programming/Kotlin

[Kotlin] ๋‚ ์งœ Date ์‹œ์ž‘์ผ๋ถ€ํ„ฐ ์ข…๋ฃŒ์ผ๊นŒ์ง€ ํ•˜๋ฃจ์”ฉ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•, ์ฝ”ํ‹€๋ฆฐ ๋ฐ˜๋ณต๋ฌธ ๋Œ๋ฆฌ๊ธฐ

yuri lee 2023. 1. 14. 23:22
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์ฝ”ํ‹€๋ฆฐ์—์„œ ์‹œ์ž‘์ผ๋ถ€ํ„ฐ ์ข…๋ฃŒ์ผ๊นŒ์ง€ ํ•˜๋ฃจ์”ฉ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

 

How to do

datesUntil() ๋ฉ”์„œ๋“œ์™€, plusDays() ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์‹œ์ž‘์ผ๋ถ€ํ„ฐ ์ข…๋ฃŒ์ผ๊นŒ์ง€ 1์”ฉ ์ฆ๊ฐ€์‹œ์ผœ์ค๋‹ˆ๋‹ค. 

/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */

import java.time.LocalDate;

fun main() {
    LocalDate.of(2023, 1, 14)
    .datesUntil(LocalDate.of(2023, 1, 19).plusDays(1))
    .forEach { it -> println(it) }

}

 

์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

2023-01-14
2023-01-15
2023-01-16
2023-01-17
2023-01-18
2023-01-19
๋ฐ˜์‘ํ˜•