我尝试使用代码在Kotlin中使用javax.time:
import javax.time.calendar.LocalDate
fun main(args: Array<String>){
println("Today is ${LocalDate.now()}");
}
Run Code Online (Sandbox Code Playgroud)
并得到编译错误:
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
^
Run Code Online (Sandbox Code Playgroud)
而谷歌搜索结果显示,在科特林javax.time不能使用,人们推荐使用ThreeTenBP与ThreeTenABP如果机器人.我的用例是在Kotlin的服务器端使用javax.time类.
但是当我尝试使用TreeTenBP时,我必须导入org.threeten.bp.LocalDate而不是javax.time.calendar.LocalDateTreeTen*不是JSR-310的实现而是后端口.
除了那些backport库之外,还有什么方法可以在Kotlin中使用javax.time吗?如果是这样,如何配置这样的环境或如何编写这样的代码?