Joel Handwell
Joel Handwell

Reputation: 827

javax.time in Kotlin

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?

Upvotes: 5

Views: 1317

Answers (1)

JodaStephen
JodaStephen

Reputation: 63395

javax.time is a dead package.

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

Upvotes: 11

Related Questions