1. format the date (simpledateformat );
A. Generate a simpledateformat Class Object and specify the format. For example:
Simpledateformat SDF = new simpledateformate ("mm DD, YYYY ");
B. Call the simpledateformat Class Object format (...) method for formatting. For example:
Date = new date ();
String dateformat = SDF. Format (date );
2. Obtain the year, month, day, hour, minute, and second of the time respectively. Example: (obtain the year method)
Date = new date ();
Calender. settime (date );
Calender calender = calender. getinstance ();
Int year = calender. Get (calender. year );
3. Convert string time to time objects.For example:
String S = "04:54:20 ";
Dateformat df = newsimpledateformat ("yyyy-mm-dd hh: mm: SS ");
Try {
Dated = DF. parse (s );
System. Out. println (d );
} Catch (parseexception e ){
E. printstacktrace ();
}
Note: The time format in the string must be the same as that in the simpledateformat class object before conversion. Otherwise, an exception (Java. Text. parseexception) is thrown ).
4. Main classes used to solve time problems: