Format

Creates a new format for parsing and formatting YearMonth values.

There is a collection of predefined formats in YearMonth.Formats.

Throws

if parsing using this format is ambiguous.

Samples

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

fun main() { 
   //sampleStart 
   // Parsing and formatting YearMonth values using a custom format
val customFormat = YearMonth.Format {
    monthName(MonthNames.ENGLISH_ABBREVIATED); chars(", "); year()
}
val yearMonth = customFormat.parse("Apr, 2024")
check(yearMonth == YearMonth(2024, Month.APRIL))
val formatted = yearMonth.format(customFormat)
check(formatted == "Apr, 2024") 
   //sampleEnd
}