You can easily find the number of days in a month by using the getActualMaximum method of the Calendar class.
Until now, I added time stamps every day and looped until the month changed. .. ..
import java.util.*
fun main(args: Array<String>) {
    val calendar = Calendar.getInstance()
    val year = 2020
    val month = 2
    calendar.set(year, month - 1, 1) //Note that the month is specified starting from 0
    val maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH)
    print("${year}Year${month}The moon${maxDay}There is a day")
}
Recommended Posts