. 1 Import the java.text.DateFormat;
2 Import java.text.ParseException;
. 3 Import the java.text.SimpleDateFormat;
. 4 Import java.util.Date;
. 5
. 6 public class the Test {
. 7
. 8 public static void main (String [] args) {
9 // initialize a date type, attention to initial values
10 Date date = null ;
. 11 // If a new Date object directly, the system uses a time
12 is Date SystemDate = new Date ();
13 is //Here the use of a simple transition new date format object that specifies the format (year - month - day)
14 DateFormat format = new SimpleDateFormat ( "yyyy-MM-dd" );
15 // specify the format (year - month - Day : minutes: seconds)
16 DateFormat = format1 new new the SimpleDateFormat ( "the mM-dd-YYYY HH: mm: SS" );
. 17 the try {
18 is // by the method of forming the format object custom date
. 19 dATE = format.parse ( "2019 -5-21 " );
20 is } the catch (a ParseException E) {
21 is e.printStackTrace ();
22 is }
23 is // date not specified format, the output of the system acquisition
24 System.out.println ( "current system date:" + SystemDate);
25 // annual output system acquired - month - May
26 System.out.println ( "current system date:" + format1.format (SystemDate));
27 // output system acquired year - month - day hour: min: sec
28 System.out.println ( "current system date:" + format.format (SystemDate));
29 // annual output custom - month - day
30 System.out.println ( "date from the definition:" + format.format (dATE));
31 is
32 }
33 is
34 is }