Root directory Java.Util. DateIn addition to SQL statements Java.SQL. DateIt is used for SQL statements. It only contains the date and no time. It has the gettime method that returns the number of milliseconds, and can be directly constructed. Java.Util. DateD = new Java.Util. Date(Sqldate. gettime ()); ... -------------------------------------------------------------------------------- JAVA. util. date is Java. SQL. date parent class (note spelling) the former is a commonly used class that represents time, we usually use it to format or obtain the current time when reading and writing the database after the latter, because the setdate () parameter of preparedstament and getdate () of resultset () the 2nd parameters of the method are all Java. SQL. date conversion is JAVA. SQL. date date = new Java. SQL. date (); JAVA. util. date d = new Java. util. date (date. gettime (); the opposite is the same -------------------------------------------------------------------------------- Inheritance relationship: Java. Lang. Object -- "Java.Util. Date-- "Java.SQL. Date The specific conversion relationship is Java.Util. DateD = new Java.Util. Date(New Java.SQL. Date()); -------------------------------------------------------------------------------- SQL. Date, Usually in the database time field,Util. DateGenerally, it is a daily Date Field. -------------------------------------------------------------------------------- Java.SQL. DateIt is mainly used in SQL! Java.Util. DateIn a normal environment! -------------------------------------------------------------------------------- Simpledateformat F = new simpledateformat ("yyyy-mm-dd hh: mm: SS "); Java.Util. DateUtildate = new date (); Java.SQL. DateSqldate = new Java.SQL. Date(Utildate. gettime ()); Java. SQL. Time stime = new java. SQL. Time (utildate. gettime ()); Java. SQL. timestamp STP = new java. SQL. timestamp (utildate. gettime ()); System. Out. println (utildate. getyear ()); All the time and date can be formatted by simpledateformat format () F. Format (STP); F. Format (stime); F. Format (sqldate); F. Format (utildate) Java.SQL. DateSqldate = Java.SQL. Date. Valueof ("2005-12-12 ");
Utildate = new Java.Util. Date(Sqldate. gettime ()); Bytes -------------------------------------------------------------------------------------------------- The alternative method is to get the year, month, and day: Import java. Text. simpledateformat; Import java. util .*; Java.Util. DateDate = 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 ); |