I'm converting some code from using Java 8's LocalDatetime
to using the version from kotlinx-datetime
and I can't find any formatting methods. Specifically, I'm replacing a FormatStyle.MEDIUM
. Do they not exist and I need to write the formatting?
This is for an Android app. Is there are there Android specific libraries I can use? Or can I do this with pre-Java 8 methods to maintain support for older versions of Android?
Edit (my solution based on the answer from Arvind):
fun Instant.toDateTimeString(formatStyle: FormatStyle = FormatStyle.MEDIUM): String {
val localDatetime = toLocalDateTime(TimeZone.currentSystemDefault())
val formatter = DateTimeFormatter.ofLocalizedDateTime(formatStyle)
return formatter.format(localDatetime.toJavaLocalDateTime())
}