java.text.DateFormat (JDK 1.1)
This class formats and parses dates and times in a locale-specific way. As an abstract class, it cannot be instantiated directly, but it provides a number of static methods that return instances of a concrete subclass which you can use to format dates in a variety of ways. The getDateInstance() methods return a DateFormat object suitable for formatting dates in either the default locale or a specified locale. A formatting style may also optionally be specified--the constants FULL, LONG, MEDIUM, SHORT, and DEFAULT specify this style. Similarly, the getTimeInstance() methods return a DateFormat object that formats and parses times, and the getDateTimeInstance() methods return a DateFormat object that formats both dates and times. These methods also optionally take a format style constant and a Locale. Finally, getInstance() returns a default DateFormat object that formats both dates and times in the SHORT format.
Once you have created a DateFormat object, you can use the setCalendar() and setTimeZone() methods if you want to format the date using a calendar or time zone other than the default.
The various format() methods convert java.util.Date objects to strings, using whatever format is encapsulated in the DateFormat object. The parse() and parseObject() methods perform the reverse operation--they parse a string formatted according to the rules of the DateFormat object and convert it into a Date object.
The DEFAULT, FULL, MEDIUM, LONG, and SHORT constants are used to specify how verbose or compact the formatted date or time should be. The remaining constants, which all end with _FIELD, specify various fields of formatted dates and times and are used with the FieldPosition object that is optionally passed to format().
public abstract classDateFormatextends Format implements Cloneable { //Protected ConstructorprotectedDateFormat(); //Format Style Constantspublic static final intDEFAULT; public static final intFULL; public static final intLONG; public static final intMEDIUM; public static final intSHORT; //Date and Time Field Constantspublic static final intERA_FIELD; public static final intYEAR_FIELD; public static final intMONTH_FIELD; public static final intWEEK_OF_MONTH_FIELD,WEEK_OF_YEAR_FIELD; public static final intDATE_FIELD,DAY_OF_YEAR_FIELD; public static final intDAY_OF_WEEK_FIELD,DAY_OF_WEEK_IN_MONTH_FIELD; public static final intTIMEZONE_FIELD; public static final intAM_PM_FIELD; public static final intHOUR0_FIELD,HOUR1_FIELD; public static final intHOUR_OF_DAY0_FIELD,HOUR_OF_DAY1_FIELD; public static final intMINUTE_FIELD; public static final intSECOND_FIELD; public static final intMILLISECOND_FIELD; //Protected Instance Variablesprotected Calendarcalendar; protected NumberFormatnumberFormat; //Class Methodspublic static Locale[]getAvailableLocales(); public static final DateFormatgetDateInstance(); public static final DateFormatgetDateInstance(intstyle); public static final DateFormatgetDateInstance(intstyle, LocaleaLocale); public static final DateFormatgetDateTimeInstance(); public static final DateFormatgetDateTimeInstance(intdateStyle, inttimeStyle); public static final DateFormatgetDateTimeInstance(intdateStyle, inttimeStyle, LocaleaLocale); public static final DateFormatgetInstance(); public static final DateFormatgetTimeInstance(); public static final DateFormatgetTimeInstance(intstyle); public static final DateFormatgetTimeInstance(intstyle, LocaleaLocale); //Public Instance Methodspublic Objectclone(); //Overrides Formatpublic booleanequals(Objectobj); //Overrides Objectpublic final StringBufferformat(Objectobj, StringBuffertoAppendTo, FieldPositionfieldPosition); //Defines Formatpublic abstract StringBufferformat(Datedate, StringBuffertoAppendTo, FieldPositionfieldPosition); public final Stringformat(Datedate); public CalendargetCalendar(); public NumberFormatgetNumberFormat(); public TimeZonegetTimeZone(); public inthashCode(); //Overrides Objectpublic booleanisLenient(); public Dateparse(Stringtext) throws ParseException; public abstract Dateparse(Stringtext, ParsePositionpos); public ObjectparseObject(Stringsource, ParsePositionpos); //Defines Formatpublic voidsetCalendar(CalendarnewCalendar); public voidsetLenient(booleanlenient); public voidsetNumberFormat(NumberFormatnewNumberFormat); public voidsetTimeZone(TimeZonezone); }
Hierarchy:
Object->Format(Serializable, Cloneable)->DateFormat(Cloneable)
Extended By:
SimpleDateFormat
Returned By:
DateFormat.getDateInstance(), DateFormat.getDateTimeInstance(), DateFormat.getInstance(), DateFormat.getTimeInstance()