2

I use Hibernate and I have a datetime in my MySQL database. Now I want to store the date/time which is a java.util.Date into the database.

So I can write:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
testObject.setCreationDate(df.parse("2010-06-06 13:20:15"));

But how can I set the current date/time? Because this is a data field which should store the creation datetime of this object/table row.

Best Regards.

1 Answer 1

3
Date date = new java.sql.Date();

will create the date object with the current date/time.

Sign up to request clarification or add additional context in comments.

1 Comment

They're using java.util.Date instead, but it works the same way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.