1 /*2 1. Get the current time of the system3 2.date-->string4 3.string-->date5 */6 Importjava.util.Date;7 ImportJava.text.SimpleDateFormat;8 9 Public classTest02Ten { One Public Static voidMain (string[] args)throwsexception{ A - - //Get system Current time theDate Nowtime =NewDate (); - - //java.util.Date; class has overridden the ToString method -System.out.println (Nowtime);//Sun Dec 15:35:05 CST + - //================================================ + //date-->string A //formatted Date (a string that converts a date type to a specific format in a process) at - //1. Create date Format Object -SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss SSS"); - //SimpleDateFormat sdf = new SimpleDateFormat ("yyyy year MM-DD HH:mm:ss SSS"); - - //2. Formatting of the finish date of the calling format method inString Strnowtime =Sdf.format (nowtime); - toSystem.out.println (Strnowtime);//2012-12-30 15:40:13 390 + - //========================================= the //string-->date * //1. Create date Format Object $SimpleDateFormat DateFormat =NewSimpleDateFormat ("Yyyy-mm-dd");Panax Notoginseng - //2. Given a date string theString time = "2008-08-08";//The format must be the same as the format specified in SimpleDateFormat. + A //3. Call the Parse method theDate T =Dateformat.parse (time); + -System.out.println (t);//Fri 00:00:00 CST $ $ - } -};
Time Formatting Exercises