我尝试使用以下代码在 Kotlin 中使用 javax.time:
import javax.time.calendar.LocalDate
fun main(args: Array<String>){
println("Today is ${LocalDate.now()}");
}
并出现编译错误:
C:\kotlin-hello-world>kotlinc hello.kt -include-runtime -d hello.jar
hello.kt:1:14: error: unresolved reference: time
import javax.time.calendar.LocalDate
^
Google 搜索显示 Kotlin javax.time 无法使用,建议使用 ThreeTenBP与 ThreeTenABP如果是安卓的话。我的用例是在服务器端使用 Kotlin 的 javax.time 类。
但是当我尝试使用 TreeTenBP 时,我必须导入 org.thirden.bp.LocalDate
而不是 javax.time.calendar.LocalDate
因为 TreeTen* 不是JSR-310 的实现但向后移植。
除了那些向后移植库之外,还有什么方法可以在 Kotlin 中使用 javax.time 吗?如果可以的话,如何配置这样的环境或者如何编写这样的代码?
最佳答案
javax.time
是一个死包。
在 Java SE 8 中使用 java.time
。
或者用于向后移植的org.thirden.bp
。
关于java-8 - Kotlin 中的 javax.time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38487906/