1 The time type in Java java.sql the three database-related datetime types under the package, respectively:? Date: Represents a day, only a month or so, no time or seconds. will lose time;? Time: The hour, day and minute; ----Date getTime ()
2The conversion of time types to the java.util.Date of the three time types of the database is basically not necessary because this is a reference to the parent class object, and no conversion is required. Java.sql.Date Date=... java.util.Date d=Date;java.sql.time Time=... java.util.Date d=Time;java.sql.timestamp Timestamp=... java.util.Date d=timestamp; When you need to convert a java.util.Date into a database of three time types, this cannot be directly assigned, which requires the use of a constructor of three time types for the database. The constructors for the date, time, and timestamp three classes under the Java.sql package require a long parameter representing the millisecond value. Creating these three types of objects requires only a millisecond value. We know that Java.util.Date has the gettime () method to get the millisecond value, then this conversion is not a problem. Java.utl.Date D=Newjava.util.Date (); Java.sql.Date Date=NewJava.sql.Date (D.gettime ());//will lose secondsTime time =NewTime (D.gettime ()); Timestamp Timestamp=NewTimestamp (D.gettime ());
Java (Time, Imestamp, data) conversion