我正在使用这个库:实现(“com.github.thellmund.Android-Week-View:core:5.2.4”)
在我的日历适配器中,我使用此方法:
override fun onRangeChanged(firstVisibleDate: LocalDate, lastVisibleDate: LocalDate) {
onRangeChange(firstVisibleDate)
}
参数firstVisibleDate是一个Java LocalDate对象,但我想将此localDate转换为ThreeTen LocalDate以使用版本< 26
有没有办法将 Java LocalDate 转换为 ThreeTen LocalDate?我正在使用当前的最小 api 23。
您可以在 API 23 上使用 Java
LocalDate
以及 Java 8+ API 脱糖支持:
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
isCoreLibraryDesugaringEnabled = true
}
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
}
如果您仍然需要将其转换为 ThreeTen
LocalDate
,您可以使用其中一种工厂方法:
val threeTenDate = LocalDate.ofEpochDay(firstVisibleDate.toEpochDay())