Hi. is there a library to get a string like "time ...
# multiplatform
h
Hi. is there a library to get a string like "time ago" for KMM?
1
h
Depending on your use case one very very simple option would be Duration.toString
s
I use the android.icu.text.RelativeDateTimeFormatter on Android, which is available for JVM through icu4j. Apple has it’s own RelativeDateTimeFormatter for that. This gives you something like „7 minutes ago“ or „vor 7 Minuten“
h
@Stefan Oltmann so you are using expect/actual to do this?
s
Not in my case, but it’s possible.
h
@ephemient is there an example code to try this?
found this article it uses ktx date-time but not like time ago style https://betterprogramming.pub/date-formatting-with-kotlin-multiplatform-1329a2b75bb
s
Yeah, I don’t think kotlinx Datetime has RelativeDateFormat or IntervalDateFormat yet
Both are provided through icu
e
kotlin doesn't have any multiplatform concept of "locale" and kotlinx-datetime doesn't have any locale-aware formatting
h
decided to use platform spesific implementations for iOS and Android. Thank you everyone