views:

117

answers:

1

Hello!

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.

+2  A: 
Date date = new java.sql.Date();

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

dplass
They're using `java.util.Date` instead, but it works the same way.
R. Bemrose
So easy... thanks a lot!
Tim