Given a `LocalDate`, how do I format it as a local...
# kotlinx-datetime
h
Given a
LocalDate
, how do I format it as a localized string?
java.time.LocalDate()
has a
format()
method, but the kotlinx version doesn't, and so far my google searches are unsuccessful.
h
Thanks for the reply. I ended up with this stopgap:
Copy code
fun LocalDate.toJavaLocalDate(): java.time.LocalDate {
    return java.time.LocalDate.ofEpochDay(this.toEpochDays().toLong())
}

someLocalDate.toJavaLocalDate().format(DateTimeFormatter.ofPattern("LLL dd"))
j
if you're using the library in Kotlin Multiplatform code then there's example of setting up that formatter for various platforms in https://github.com/joreilly/Confetti
h
Thanks, that'll be helpful as we're attempting to convert our Android project to KMM now.
726 Views