Format
actual fun Format(block: DateTimeFormatBuilder.WithDate.() -> Unit): DateTimeFormat<LocalDate>(source)
expect fun Format(block: DateTimeFormatBuilder.WithDate.() -> Unit): DateTimeFormat<LocalDate>(source)
Creates a new format for parsing and formatting LocalDate values.
Only parsing and formatting of well-formed values is supported. If the input does not fit the boundaries (for example, dayOfMonth is 31 for February), consider using DateTimeComponents.Format instead.
There is a collection of predefined formats in LocalDate.Formats.
Throws
if parsing using this format is ambiguous.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() {
//sampleStart
// Parsing and formatting LocalDate values using a custom format
val customFormat = LocalDate.Format {
monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year()
}
val date = customFormat.parse("Apr 16, 2024")
check(date == LocalDate(2024, Month.APRIL, 16))
val formatted = date.format(customFormat)
check(formatted == "Apr 16, 2024")
//sampleEnd
}
actual fun Format(block: DateTimeFormatBuilder.WithDate.() -> Unit): DateTimeFormat<LocalDate>(source)
actual fun Format(block: DateTimeFormatBuilder.WithDate.() -> Unit): DateTimeFormat<LocalDate>(source)