Long time no use of MySQL, and found that a small number of times problems also encountered a lot of trouble, hehe
So to sum up:
First type:
Date time= New Java.sql.Date (New Java.util.Date (). GetTime ());
The second type:
Java with PreparedStatement to Setdate, with the form of a question mark to the date question mark assignment
Pstmt.settimestamp (8, New Timestamp (System.currenttimemillis ()));
Pstmt.setdate (1, New Java.sql.Date (Date1.gettime ()));
Pstmt.setdate (2, New Java.sql.Date (Date2.gettime ()));
Third:
In fact, inserting a time field into the MySQL database is also very easy, as long as the java.util.Date type is set to the Hibernate Pojo class object, Pojo.set (new Java.util.Date ());
Relevant information found on the Internet in the following appendix:
Mysql and Java Time type
The time type of
MySQL has the corresponding time type in Java
Date Java.sql.Date
Datetime Java.sql.Timestamp
Timestamp Java.sql.Timestamp
Time Java.sql.Time
Year Java.sql.Date
the following ways to achieve it:
date = new Date ();//Get system time.
String nowtime = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). Format (date);//Converts the time format to a format that conforms to the timestamp requirement.
Timestamp goodsc_date = timestamp.valueof (nowtime);//convert Time to
Java.util.Date is the parent class of Java.sql.Date