monthNumber

abstract fun monthNumber(padding: Padding = Padding.ZERO)(source)

A month-of-year number, from 1 to 12.

By default, it's padded with zeros to two digits. This can be changed by passing padding.

Samples

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

fun main() { 
   //sampleStart 
   // Using month number with various paddings in a custom format
val zeroPaddedMonths = LocalDate.Format {
    monthNumber(); char('/'); dayOfMonth(); char('/'); year()
}
check(zeroPaddedMonths.format(LocalDate(2021, 1, 13)) == "01/13/2021")
check(zeroPaddedMonths.format(LocalDate(2021, 12, 13)) == "12/13/2021")
val spacePaddedMonths = LocalDate.Format {
    monthNumber(padding = Padding.SPACE); char('/'); dayOfMonth(); char('/'); year()
}
check(spacePaddedMonths.format(LocalDate(2021, 1, 13)) == " 1/13/2021")
check(spacePaddedMonths.format(LocalDate(2021, 12, 13)) == "12/13/2021") 
   //sampleEnd
}