ZERO

Pad with zeros during formatting. During parsing, padding is required; otherwise, parsing fails.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   // Defining a custom format that uses '0' for padding
val format = LocalDate.Format {
    monthNumber(Padding.ZERO) // padding with zeros is the default, but can be explicitly specified
    char('/')
    dayOfMonth()
    char(' ')
    year()
}
val leoFirstReignStart = LocalDate(457, 2, 7)
check(leoFirstReignStart.format(format) == "02/07 0457")
check(LocalDate.parse("02/07 0457", format) == leoFirstReignStart)
try {
    LocalDate.parse("02/7 0457", format)
    fail("Expected IllegalArgumentException")
} catch (e: IllegalArgumentException) {
    // parsing without padding is not allowed, and the day-of-month was not padded
} 
   //sampleEnd
}