dayOfMonth

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

A day-of-month number, from 1 to 31.

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 day-of-month with various paddings in a custom format
val zeroPaddedDays = LocalDate.Format {
    dayOfMonth(); char('/'); monthNumber(); char('/'); year()
}
check(zeroPaddedDays.format(LocalDate(2021, 1, 6)) == "06/01/2021")
check(zeroPaddedDays.format(LocalDate(2021, 1, 31)) == "31/01/2021")
val spacePaddedDays = LocalDate.Format {
    dayOfMonth(padding = Padding.SPACE); char('/'); monthNumber(); char('/'); year()
}
check(spacePaddedDays.format(LocalDate(2021, 1, 6)) == " 6/01/2021")
check(spacePaddedDays.format(LocalDate(2021, 1, 31)) == "31/01/2021") 
   //sampleEnd
}