LoginSignup
0
0

More than 1 year has passed since last update.

【Kotlin/JVM】17歳とMヶ月とD日

Last updated at Posted at 2022-12-03

「17歳とMヶ月とD日」の計算

import java.time.LocalDate
import java.time.temporal.ChronoUnit

fun main() {
    val birthDate = LocalDate.parse("1964-09-25")
    val currentDate = LocalDate.now()

    var date = birthDate
    val years = 17L

    date = date.plusYears(years)
    val months = ChronoUnit.MONTHS.between(date, currentDate)

    date = date.plusMonths(months)
    val days = ChronoUnit.DAYS.between(date, currentDate)

    println("${years}歳と${months}ヶ月と${days}日")
}

 →Kotlin Playground

/以上

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