https://kotlinlang.org logo
#kotlinx-datetime
Title
# kotlinx-datetime
h

humblehacker

08/12/2022, 8:52 PM
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

humblehacker

08/12/2022, 9:10 PM
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

John O'Reilly

08/12/2022, 10:01 PM
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

humblehacker

08/12/2022, 10:06 PM
Thanks, that'll be helpful as we're attempting to convert our Android project to KMM now.
389 Views