http://www.verejava.com/?id=16993074079095
/** Knowledge Points: Date dates class */import Java.util.date;import java.text.simpledateformat;public class testdate{public static void Main (string[] args) {//Get system Current date date=new date (); SYSTEM.OUT.PRINTLN (date); Obtained year System.out.println (Date.gettime ()); Get current DateTime System.out.println (Cdate.getcurrentdatetime ()); System.out.println (Cdate.stringtodate ("2000-12-12 00:00:00")); }}class cdate{/** Gets the current datetime string */public static string GetCurrentDateTime () {Date date=new D Ate (); The format of the date SimpleDateFormat df=new simpledateformat ("Yyyy-mm-dd HH:mm:ss"); String Datestr=df.format (date). toString (); return datestr; }/** date is converted to a formatted string */public static string datetostring (date date) {//Date formatted simple DateFormat df=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String Datestr=df.format (date). toString (); return datestr; } /** String converted to date */public static date Stringtodate (String datestring) {try{SimpleDateFormat Df=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Return Df.parse (datestring); }catch (Exception e) {e.printstacktrace (); return null; } }}
http://www.verejava.com/?id=16993074079095
A date date class for Java common class libraries