Skip to content
Advertisement

Convert LocalDate to LocalDateTime or java.sql.Timestamp

I am using JodaTime 1.6.2.

I have a LocalDate that I need to convert to either a (Joda) LocalDateTime, or a java.sqlTimestamp for ormapping.

The reason for this is I have figured out how to convert between a LocalDateTime and a java.sql.Timestamp:

JavaScript

So, if I can just convert between LocalDate and LocalDateTime, then I can make the continued conversion to java.sql.Timestamp. Thanks for any nudges in the right direction!

Advertisement

Answer

JodaTime

To convert JodaTime’s org.joda.time.LocalDate to java.sql.Timestamp, just do

JavaScript

To convert JodaTime’s org.joda.time.LocalDateTime to java.sql.Timestamp, just do

JavaScript

JavaTime

To convert Java8’s java.time.LocalDate to java.sql.Timestamp, just do

JavaScript

To convert Java8’s java.time.LocalDateTime to java.sql.Timestamp, just do

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement