Kapil Bhagia
Kapil Bhagia

Reputation: 85

Current date time in Java using Joda time in mySQL type date time format

I am using Hibernate and trying to make the string that will hold the current date time for the database insert using session.save() method. I need the String object as output in mySQL date time format. Something like this:

`System.out.println(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").parseDateTime(new DateTime().toString()));`

Just a call out that the about statement doesn't work.

Upvotes: 0

Views: 458

Answers (1)

GreyBeardedGeek
GreyBeardedGeek

Reputation: 30088

Instead of trying to create a string representation of the DateTime object, you should just store it directly.

For an example, see How to persist JSR 310 java.time.LocalDateTime in JPA with Hibernate using usertype

Upvotes: 1

Related Questions