javax.time in Kotlin
Asked Answered
P

1

5

I tried following code to use javax.time in Kotlin:

import javax.time.calendar.LocalDate

fun main(args: Array<String>){
  println("Today is ${LocalDate.now()}");
}

And got compilation error:

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
             ^

And google search shows in Kotlin javax.time can not be used and people recommend to use ThreeTenBP with ThreeTenABP if android. My use case is use javax.time classes in server side with Kotlin.

But when I tried to use TreeTenBP, I have to import org.threeten.bp.LocalDate instead of javax.time.calendar.LocalDate as TreeTen* is not implementation of JSR-310 but back port.

Is there any way to use javax.time in Kotlin other than those backport libraries? If so, how to configure such environment or how to write such code?

Pleasantry answered 20/7, 2016 at 18:13 Comment(2)
What version of the JDK are you using?Adorne
java -version --> java version "1.8.0_92"Pleasantry
S
11

javax.time is a dead package.

Use java.time in Java SE 8. Or org.threeten.bp for the backport.

Sinusoid answered 20/7, 2016 at 18:23 Comment(2)
I was about to suggest JodaTime as an alternative for java 6 or 7, but if the author of that library himself is suggesting you use a backport of java.time...Preinstruct
@Preinstruct He is also the specification lead for JSR 310Broadcast

© 2022 - 2024 — McMap. All rights reserved.