Partho Paul
04/26/2022, 9:41 AMval date = LocalDateTime.parse(isoValue)
val dateFormat = DateTimeFormatter.ofPattern(format)
return date.format(dateFormat)
This is giving me an error which says that DateTimeFormatter.ofPattern(format)
needs a Locale but I'm not getting any option to set Locale by doing something like DateTimeFormatter.ofPattern(format).withLocale(Locale.ENGLISH)
because Locale
is just an interface without any implementation. Tried googling but didn't find anything. Is there any other way to do this?
TIArocketraman
04/26/2022, 12:48 PMrocketraman
04/26/2022, 12:49 PMDate.toLocaleTimeString
and looks like this:
actual fun formatDateTime(date: LocalDateTime, locale: String): String =
jsFormatDateTime(date.year, date.monthNumber - 1, date.dayOfMonth, date.hour, date.minute, locale)
@Suppress("UNUSED_PARAMETER", "LongParameterList")
private fun jsFormatDateTime(yearArg: Int, monthArg: Int, dayArg: Int, hourArg: Int, minuteArg: Int, locale: String): String =
js(
"(new Date(yearArg, monthArg, dayArg, hourArg, minuteArg))" +
".toLocaleTimeString(locale, {year: 'numeric', month: 'short', day: '2-digit'});"
) as String
rocketraman
04/26/2022, 12:50 PMen-US
.Luc Girardin
04/26/2022, 3:18 PMPartho Paul
04/27/2022, 11:17 AMrocketraman
04/27/2022, 12:48 PM