Raed Ghazal
10/08/2023, 8:54 AMkotlinx.datetime
might be helpful to others, specially if you’re moving from java.time
package and struggling to find alternatives for its usages
https://raed-o-ghazal.medium.com/kotlinx-localdatetime-manipulation-for-kmm-eacfede93abaChristiano
11/24/2023, 9:24 AMjs-joda/locale
is not added, but can't seem to find anything regarding that in conjunction with KMP 😅Raed Ghazal
11/24/2023, 10:12 AMChristiano
11/24/2023, 10:36 AMval formatter = DateTimeFormatter.ofPattern("MMMM yyyy")
val fromDate = LocalDateTime.parse(from, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))
val toDate = LocalDateTime.parse(to, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))
"${formatter.format(fromDate)} - ${formatter.format(toDate)}"
And the import qualifiers are all from this package
kotlinx.datetime.internal.JSJoda.*
Raed Ghazal
11/24/2023, 10:42 AMChristiano
11/24/2023, 10:43 AMkotlinx.datetime.*
import qualifier I noticed there where other functions I could use, by using this I can actually change the format of the string dependent on the Locale
val localeOptions = dateLocaleOptions {
month = "short"
year = "numeric"
}
val fromDateFormatted = LocalDateTime.parse(from).toInstant(TimeZone.UTC).toJSDate().toLocaleString("en", localeOptions)
val toDateFormatted = LocalDateTime.parse(to).toInstant(TimeZone.UTC).toJSDate().toLocaleString("en", localeOptions)
"$fromDateFormatted - $toDateFormatted"
When not adding "en" as a Locale, the browser/device Locale seems to be used.Raed Ghazal
11/24/2023, 11:10 AMany case, thanks for your replies and the article!sure, glad to help, a follow on medium and maybe some claps can help me as well 😄
Christiano
11/24/2023, 11:11 AMRaed Ghazal
11/24/2023, 11:12 AM