0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Kotlin/JVM】一定期間ごとの日付を出力する

Posted at

一定期間ごとの日付を出力する。

import java.time.LocalDate

fun main() {
    // 起点の日付
    val initial: String = "2022-06-18"
    // 間隔[日]
    val interval: Long = 10
    // 出力回数
    val count: Int = 5

    sequence {
        var date = LocalDate.parse(initial)
        while(true) {
            date = date.plusDays(interval)
            yield(date)
        }
    }.take(count)
        .forEach { println(it) }
}

出力結果

2022-06-28
2022-07-08
2022-07-18
2022-07-28
2022-08-07

/以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?