The format date uses the SimpleDateFormat class;
The Date object (java.util.Date) is formatted as text through the format () method of the instance, and the text is parsed into a Date object (Java.util.Date) by the parse () method.
Note: When instantiated through the SimpleDateFormat SDF = new SimpleDateFormat (), the current default time zone is used as the time zone for subsequent formatting, parsing operations, even if the default time zone is reset in subsequent code SimpleDateFormat the time zone value of the instance.
Set date and time mode when initializing
simpledateformat sdf = new SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss. SSS ");
Modify the date and time pattern
sdf.applypattern ("Yyyy/mm/dd HH:mm:ss. SSS ")
Sdf.format (New Date ());
Date and time pattern results
"yyyy. Mm.dd G ' at ' HH:mm:ss z ' 2001.07.04 AD at 12:08:56 PDT EEE
, MMM D, ' yy ' Wed, June 4, '
h:mm a ' 12 : The PM
"hh ' o ' clock ' A, zzzz" o ' clock PM, Pacific Daylight Time
"k:mm A, z" 0:08 PM, PDT
"yyy Yy. MMMMM.DD GGG hh:mm aaa " 02001.july.04 AD 12:08 PM
" EEE, D MMM yyyy HH:mm:ss Z " Wed, 4 June 2001 12:08:56-07 "
yymmddhhmmssz" 010704120856-0700 "
yyyy-mm-dd ' T ' HH:mm:ss". Sssz " 2001-07-04t12:08:56.235-0700
If you get a date, say you need to take yesterday's formatted date, you need to use the Java.util.Calendar class, which is now a very convenient class.
Paired with SimpleDateFormat.
Calendar cal = calendar.getinstance ();
Cal.add (Calendar.date, -1);
String yesterday = new SimpleDateFormat ("Yyyy-mm-dd"). Format (Cal.gettime ());
System.out.println (yesterday);
And so on, you can customize other types of data.