3

I am working on a project that uses a shared library which uses org.threeten for Date/Time. As the library is shared across many projects it cannot be upgraded to Java 8 yet (sigh). The shortest way seems to be toString()/parse() combination

java.time.OffsetDateTime.parse(org.threeten.bp.OffsetDateTime.toString())
java.time.LocalDate.parse(org.threeten.bp.LocalDate.toString())

But more efficient way in terms of garbage creation will probably be the use of .of(...) methods:

java.time.OffsetDateTime.of(tt.getYear(), tt.getMonth(), tt.getDayOfMonth(), ...)

Have you stumbled upon a library that provides all this sort of conversions between Joda, Threeten and java.time classes?

klor
  • 3,596
  • 2
  • 13
  • 13
  • I would get the millis since the epoch and the offset id, then you only have two fields to pass rather than all of them. – Boris the Spider Sep 21 '15 at 22:16
  • @BoristheSpider you can do that as well. But as with the toString()/parse() methods it will have the overhead of calculating each field back from the instant since epoch. Java 8 time classes internally store all the fields separately (point 4 http://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html). – klor Sep 21 '15 at 22:30

1 Answers1

2

The neatest way would be to fork ThreeTen-Backport and make the termporal interfaces extend their Java 8 counterparts. That way, you could do OffsetDateTime.from(threeTenOffsetDateTime) and so on.

I'm not aware of any existing fork that does this.

JodaStephen
  • 60,927
  • 15
  • 95
  • 117