Before Java8, I used Joda's DateTime
class to include timezone information and I can easily to convert between DateTime
and sql Timestamp
.
Once migrate to Java8, which class I should replace? OffsetDateTime
or ZonedDateTime
?
Also, I tried to use OffsetDateTime
, but it seems can't construct back to OffsetDateTime
from a sql Timestamp
.
For Joda DateTime
and Timestamp
converter, the code is like:
val joda = DateTime.now()
val sqlJoda = new Timestamp(joda.getMillis)
val jodaBack = new DateTime(sqlJoda)
But for Java8,
val java8 = OffsetDateTime.now()
val sqlJava8 = new Timestamp(java8.toInstant.toEpochMilli)
val java8Back = ???
Anyone has some idea about that? It seems Joda DateTime
is really good.