toString

actual open override fun toString(): String(source)
expect open override fun toString(): String(source)

Converts this year-month to the extended ISO 8601 string representation.

See also

for the format details.

for the dual operation: obtaining YearMonth from a string.

for formatting using a custom format.

Samples

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

fun main() { 
   //sampleStart 
   // Converting YearMonth values to strings
check(YearMonth(2024, 4).toString() == "2024-04")
check(YearMonth(12024, 4).toString() == "+12024-04")
check(YearMonth(-2024, 4).toString() == "-2024-04") 
   //sampleEnd
}
actual open override fun toString(): String(source)