Sunny
03/04/2022, 10:38 AMinternal expect fun formatDate(value: Long, format: String): String
is straight forward. For JavaScript in Kotlin/JS is there any equivalent for formatting the date.
kotlin.js.Date
has no formatting capabilities.
kotlinx-datetime
also seems to lack formatting capabilities. Am I missing something trivial?Andrey Chernov
03/04/2022, 11:15 AMSunny
03/04/2022, 1:42 PMMustafa Ozhan
03/04/2022, 2:31 PMfun Instant.toDateString(
timeZone: TimeZone = TimeZone.currentSystemDefault()
) = toLocalDateTime(timeZone).run {
"${hour.doubleDigits()}:${minute.doubleDigits()} " +
"${dayOfMonth.doubleDigits()}.${monthNumber.doubleDigits()}.${year.doubleDigits()}"
}
Mustafa Ozhan
03/04/2022, 2:31 PMdoubleDigits
is
fun Int.doubleDigits() = if (this <= BIGGEST_DIGIT) "0$this" else "$this"