YearMonth

actual constructor(year: Int, month: Month)(source)
actual constructor(year: Int, month: Int)(source)
expect constructor(year: Int, month: Month)(source)

Constructs a YearMonth instance from the given year-month components.

The range for year is unspecified, but at least is enough to represent year-months of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE in any time zone.

Throws

if year is out of range.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlinx.datetime.onDay
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Constructing a YearMonth value using its constructor
val yearMonth = YearMonth(2024, Month.APRIL)
check(yearMonth.year == 2024)
check(yearMonth.month == Month.APRIL) 
   //sampleEnd
}

expect constructor(year: Int, month: Int)(source)
actual constructor(year: Int, month: Month)(source)
actual constructor(year: Int, month: Int)(source)