This problem is summarized as follows:
Java. SQL. date is a subclass of Java. util. date. A thin package that encapsulates millisecond values allows JDBC to mark millisecond values as SQL date values. To be consistent with the definition of SQL date. SQL. the millisecond value encapsulated by the date instance must be specified by setting the time, minute, second, and millisecond to zero in a specific time zone related to the instance.
The corresponding methods in Java. util. date have been discarded. You should use the calendar class to replace the date and time fields, and use the dateformat class to format and analyze the date string.
Installation and replacement between them: Java. utl. date is used in addition to SQL statements. SQL. date is used for SQL statements. It only contains the date but does not have time. It has the gettime method that returns the number of milliseconds. Naturally, you can directly build Java. util. date d = new Java. util. date (SQL. date. gettime (); Java. SQL. date = new Java, SQL. date (); Java. util. date d = new Java. util. date (date. gettime ());
The alternative method is to get the year, month, and day:
Import java. Text. simpledateformat;
Import java. util .*;
Java. util. Date = new java. util. Date ();
// If you want to obtain the format of yyyymmdd simpledateformat
Sy1 = new simpledateformat ("yyyymmdd ");
String dateformat = sy1.format (date );
// If You Want To separately obtain the year, month, and day simpledateformat
Sy = new simpledateformat ("YYYY ");
Simpledateformat Sm = new simpledateformat ("mm ");
Simpledateformat SD = new simpledateformat ("DD ");
String syear = Sy. Format (date );
String SMON = Sm. Format (date );
String SDAY = SD. Format (date );