This chapter mainly introduces DateFormat.
DateFormat Introduction
The role of DateFormat is to format and parse the date/time. In fact, it is the date formatting tool that helps us format date and then converts date into the string string we want to use
However, the DateFormat format date has limited functionality and is not simpledateformat powerful, but DateFormat is SimpleDateFormat's parent class. Therefore, we first have a general understanding of DateFormat, and then learn SimpleDateFormat.
The role of DateFormat is to format date. It supports formatting styles including full, LONG, MEDIUM and short altogether 4 kinds:
(Dateformat.short)
Full of numbers, as 12.13.52 or 3:30pm
(Dateformat.medium)
Longer, such as the 12, 1952
(Dateformat.long)
Longer, such as January 12, 1952 or 3:30:32pm
(Dateformat.full)
is fully specified, such as Tuesday, April 12, 1952 AD, or 3:30:42pm PST.
The definition of DateFormat is as follows
Public abstract class NumberFormat extends Format {}
function interface of DateFormat
Default constructor DateFormat ()//non-constructor Object clone () Boolean Equals (Object object) AB Stract stringbuffer Format (date date, StringBuffer buffer, fieldposition field) final StringBuffer format (Object object, StringBuffer buffer, fieldposition field) final String format (date date) static locale[] Geta Vailablelocales () Calendar Getcalendar () final static DateFormat getinstance () final static DateFormat Getdateinstance () Final static dateformat getdateinstance (int style) final static DateFormat getdateinstance ( int style, Locale Locale) final static DateFormat gettimeinstance () final static dateformat gettimeinstance (int st YLE) Final static dateformat gettimeinstance (int style, Locale Locale) final static DateFormat getdatetimeinstance () Final static dateformat getdatetimeinstance (int datestyle, int timestyle) final static DateFormat Getdatetimein Stance (int datestyle, inT Timestyle, Locale Locale) NumberFormat getnumberformat () TimeZone gettimezone () int hashcode () Boolean islenient () Date parse (string string) Abstract date Parse (string string, Parseposition pos ition) Object parseobject (string string, parseposition position) void Setcalendar (Calendar cal) void Setlenient (boolean value) void Setnumberformat (NumberFormat format) void Settimezone ( TimeZone TimeZone)
Note: DateFormat is an abstract class.
When we get the DateFormat instance through the DateFormat getinstance (), Getdateinstance () and Getdatetimeinstance (), the SimpleDateFormat object is actually returned.
The following function is actually the returned SimpleDateFormat object.
Final static DateFormat getinstance () final static
DateFormat gettimeinstance ()
final static DateFormat gettimeinstance (int style)
final static dateformat gettimeinstance (int style, Locale Locale)
final static DateFormat getdateinstance ()
final static dateformat getdateinstance (int style)
final static DateFormat getdateinstance (int style, Locale Locale)
final static DateFormat getdatetimeinstance ()
final static DateFormat getdatetimeinstance (int datestyle, int timestyle)
final static dateformat getdatetimeinstance (int Datestyle, int timestyle, Locale Locale)