在 ThreeTen 库 LocalDate 中转换 Java LocalDate

问题描述 投票:0回答:1

我正在使用这个库:实现(“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。

android kotlin
1个回答
0
投票

您可以在 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())
© www.soinside.com 2019 - 2024. All rights reserved.