This is the use and conversion of dates that are frequently used in common projects:
Import Java. util. date; import Java. text. parseexception; import Java. text. simpledateformat;/*** set Java. util. the date type is exchanged with the string type, and the date format * @ author administrator **/public class convertdate {/*** is specified to convert the date to the string: yyyy-mm-dd hh: mm: SS * @ Param date * @ return Str */public static string datetostr (date) {simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS "); string STR = format. format (date); Return STR;}/*** convert a date to a string: yyyy-mm-dd * @ Param date * @ return */public static string datetosimplestr (date) {simpledateformat format = new simpledateformat ("yyyy-mm-dd"); string STR = format. format (date); Return STR;}/*** string to date * @ Param Str * @ return date */public static date strtodate (string Str) {simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); Date = NULL; try {date = format. parse (STR);} catch (parseexception e) {e. printstacktrace ();} return date;}/*** Java. SQL. date and Java. util. date type conversion * @ Param sdate * @ return */public static Java. util. date sqldatetoutildate (Java. SQL. date sdate) {Java. util. date udate = NULL; long T = sdate. gettime (); udate = new date (t); Return udate;} public static Java. SQL. date utildatetosqldate (Java. util. date udate) {Java. SQL. date sdate = NULL; long T = udate. gettime (); sdate = new Java. SQL. date (t); Return sdate;} public static void main (string [] ARGs) {date = new date (); system. out. println ("date to string:" + convertdate. datetostr (date); system. out. println ("string to date:" + convertdate. strtodate (convertdate. datetostr (date )));}}