jvmMain.com.bselzer.ktx.datetime.format.BaseDateTimeFormatter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktx-datetime-jvm Show documentation
Show all versions of ktx-datetime-jvm Show documentation
Extensions for the Kotlin standard library and third-party libraries.
The newest version!
package com.bselzer.ktx.datetime.format
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toJavaLocalDateTime
import kotlinx.datetime.toLocalDateTime
abstract class BaseDateTimeFormatter : DateTimeFormatter {
protected abstract val formatter: java.time.format.DateTimeFormatter
override fun format(instant: Instant): String {
val localDate = instant.toLocalDateTime(TimeZone.currentSystemDefault()).toJavaLocalDateTime()
return formatter.format(localDate)
}
}