Java. util. Date: indicates the operation time:
Java. util. Date d1 = new java. util. Date (); // a time is created based on the current time.
Of course, you can also use another method: long times =System. currenttimemillis ();
Java. util. Date D2 = new date (times );
Java. SQL. Date: used when interacting with the database.
However, java. SQL. date is only accurate to days. That is, only (year-month-day)
Java. SQL. Date SD = new java. SQL. Date (d1.gettime ());
Or:
Java. SQL. Date SD = new java. SQL. Date (system. currenttimemillis ());
If you use Java. SQL. date to insert a database, it will not be accurate to time.
Paramentedstatement. setdate (SD); // It is only accurate to the day. If the time is not accurate, there is no problem.
If this does not meet the requirements. You can use Java. SQL. timestamp. This can be accurate to milliseconds. That is, (year-month-day hour: minute: Second. millisecond)
Paramentedstatement. settimestamp (New java. SQL. timestamp (SD. gettime ()));