java.text.DateFormat
java.text.Format
java.text.SimpleDateFormat
java.lang.Cloneable
New as of JDK 1.1
The DateFormat class formats and parses dates and times in a locale-specific manner. DateFormat is an abstract class, but it provides factory methods that return useful instances of DateFormat subclasses. These factory methods come in three groups:
Certain of these factory methods allow you to specify the style, or length, of the resulting date and time strings. The interpretation of the style parameter is locale-specific. For the locale Locale.US, the styles and their results are as follows:
Tuesday, March 04, 1997 12:00:00 o'clock AM EST
March 04, 1997 12:00:00 AM EST
04-Mar-97 12:00:00 AM
3/4/97 12:00 AM
There is also a DEFAULT style, which is equivalent to MEDIUM.
The DateFormat class defines a number of field constants that represent the various fields in formatted date and time strings. These field constants can create FieldPosition objects.
public abstract class java.text.DateFormat extends java.text.Format implements java.lang.Cloneable { // Constants public static final int AM_PM_FIELD; public static final int DATE_FIELD; public static final int DAY_OF_WEEK_FIELD; public static final int DAY_OF_WEEK_IN_MONTH_FIELD; public static final int DAY_OF_YEAR_FIELD; public static final int DEFAULT; public static final int ERA_FIELD; public static final int FULL; public static final int HOUR0_FIELD; public static final int HOUR1_FIELD; public static final int HOUR_OF_DAY0_FIELD; public static final int HOUR_OF_DAY1_FIELD; public static final int LONG; public static final int MEDIUM; public static final int MILLISECOND_FIELD; public static final int MINUTE_FIELD; public static final int MONTH_FIELD; public static final int SECOND_FIELD; public static final int SHORT; public static final int TIMEZONE_FIELD; public static final int WEEK_OF_MONTH_FIELD; public static final int WEEK_OF_YEAR_FIELD; public static final int YEAR_FIELD; // Variables protected Calendar calendar; protected NumberFormat numberFormat; // Constructors protected DateFormat(); // Class Methods public static Locale[] getAvailableLocales(); public static final DateFormat getDateInstance(); public static final DateFormat getDateInstance(int style); public static final DateFormat getDateInstance(int style, Locale aLocale); public static final DateFormat getDateTimeInstance(); public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle); public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale); public static final DateFormat getInstance(); public static final DateFormat getTimeInstance(); public static final DateFormat getTimeInstance(int style); public static final DateFormat getTimeInstance(int style, Locale aLocale); // Instance Methods public Object clone(); public boolean equals(Object obj); public final String format(Date date); public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition fieldPosition); public abstract StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition); public Calendar getCalendar(); public NumberFormat getNumberFormat(); public TimeZone getTimeZone(); public int hashCode(); public boolean isLenient(); public Date parse(String text); public abstract Date parse(String text, ParsePosition pos); public Object parseObject(String source, ParsePosition pos); public void setCalendar(Calendar newCalendar); public void setLenient(boolean lenient); public void setNumberFormat(NumberFormat newNumberFormat); public void setTimeZone(TimeZone zone); }
A field constant that represents the A.M./P.M. field.
A field constant that represents the date (day of month) field.
A field constant that represents the day-of-the-week field.
A field constant that represents the day of the week in the current month field.
A field constant that represents the day-of-the-year field.
A constant that specifies the default style.
A field constant that represents the era field.
A constant that specifies the most complete style.
A field constant that represents the zero-based hour field.
A field constant that represents the one-based hour field.
A field constant that represents the zero-based hour of the day field.
A field constant that represents the one-based hour of the day field.
A constant that specifies the long style.
A constant that specifies the medium style.
A field constant that represents the millisecond field.
A field constant that represents the minute field.
A field constant that represents the month field.
A field constant that represents the second field.
A constant that specifies the short style.
A field constant that represents the time-zone field.
A field constant that represents the week-of-the-month field.
A field constant that represents the week-of-the-year field.
A field constant that represents the year field.
A Calendar object that internally generates the field values for formatting dates and times.
A NumberFormat object that internally formats the numbers in dates and times.
This constructor creates a DateFormat.
An array of Locale objects.
This method returns an array of the Locale objects for which this class can create DateFormat objects.
A DateFormat appropriate for the default Locale that uses the default style.
This method creates a DateFormat that formats and parses dates in the default locale with the default style.
A style constant.
A DateFormat appropriate for the default Locale that uses the given style.
This method creates a DateFormat that formats and parses dates in the default locale with the given style.
public static final DateFormat getDateInstance(int style, Locale aLocale)
A style constant.
The Locale to use.
A DateFormat appropriate for the given Locale that uses the given style.
This method creates a DateFormat that formats and parses dates in the given locale with the given style.
A DateFormat appropriate for the default Locale that uses the default date and time styles.
This method creates a DateFormat that formats and parses dates and times in the default locale with the default date and time styles.
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
A style constant.
A style constant.
A DateFormat appropriate for the default Locale that uses the given data and time styles.
This method creates a DateFormat that formats and parses dates and times in the default locale with the given date and time styles.
public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)
A style constant.
A style constant.
The Locale to use.
A DateFormat appropriate for the given Locale that uses the given date and time styles.
This method creates a DateFormat that formats and parses dates and times in the given locale with the given date and time styles.
A DateFormat appropriate for the default Locale.
This method creates a general purpose DateFormat by calling getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).
A DateFormat appropriate for the default Locale that uses the default style.
This method creates a DateFormat that formats and parses times in the default locale with the default style.
A style constant.
A DateFormat appropriate for the default Locale that uses the given style.
This method creates a DateFormat that formats and parses times in the default locale with the given style.
public static final DateFormat getTimeInstance(int style, Locale aLocale)
A style constant.
The Locale to use.
A DateFormat appropriate for the given Locale that uses the given style.
This method creates a DateFormat that formats and parses times in the given locale with the given style.
A copy of this DateFormat.
Format.clone()
This method creates a copy of this DateFormat and returns it.
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if obj is an instance of DateFormat and is equivalent to this DateFormat.
The Date object to be formatted.
A string that contains a formatted representation of the date.
This method formats the given date and returns the result as a string.
public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition fieldPosition)
The object to be formatted.
A StringBuffer on which to append the formatted information.
A date or time field.
The given buffer toAppendTo with the formatted representation of the object appended to it.
Format.format(Object, StringBuffer, FieldPosition)
This method formats the given object and appends the result to the given StringBuffer. If fieldPosition refers to one of the time or date fields, its beginning and ending indices are filled with the beginning and ending positions of the given field in the resulting formatted string.
public abstract StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)
The Date object to be formatted.
A StringBuffer on which to append the formatted information.
A date or time field.
The given buffer toAppendTo with the formatted representation of the date appended to it.
This method formats the given date and appends the result to the given StringBuffer. If fieldPosition refers to one of the time or date fields, its beginning and ending indices are filled with the beginning and ending positions of the given field in the resulting formatted string.
The internal Calendar object of this DateFormat.
This method returns the Calendar object that this DateFormat uses internally.
The internal NumberFormat object of this DateFormat.
This method returns the NumberFormat object that this DateFormat uses internally.
The internal TimeZone object of this DateFormat.
This method returns the TimeZone object that this DateFormat uses internally.
A hashcode for this object.
Object.hashCode()
This method returns a hashcode for this DateFormat.
A boolean value that indicates the leniency of this DateFormat.
This method returns the current leniency of this DateFormat. A value of false indicates that the DateFormat throws exceptions when it tries to parse questionable data, while a value of true indicates that the DateFormat makes its best guess to interpret questionable data. For example, if the DateFormat is being lenient, a date such as March 135, 1997 is interpreted as the 135th day after March 1, 1997.
The string to be parsed.
The Date object represented by the given string.
If the text cannot be parsed as a date.
This method parses a date from the given string, starting from the beginning of the string.
The string to be parsed.
A ParsePosition object that can specify a position in the string.
The Date object represented by the text starting at the given position.
This method parses a date from the given string, starting from the given position. After the string has been parsed, the given ParsePosition object is updated so that its index is after the parsed text.
The string to be parsed.
A ParsePosition object that can specify a position in the string.
The object represented by the text starting at the given position.
Format.parseObject(String, ParsePosition)
This method parses a date from the given string, starting from the given position. After the string has been parsed, the given ParsePosition object is updated so that its index is after the parsed text.
The new Calendar to use.
This method sets the Calendar that this DateFormat uses internally.
A boolean value that specifies the leniency of this DateFormat.
This method sets the leniency of this DateFormat. A value of false specifies that the DateFormat throws exceptions when it tries to parse questionable data, while a value of true indicates that the DateFormat makes its best guess to interpret questionable data. For example, if the Calendar is being lenient, a date such as March 135, 1997 is interpreted as the 135th day after March 1, 1997.
The new NumberFormat to use.
This method sets the NumberFormat that this DateFormat uses internally.
The new TimeZone to use.
This method sets the TimeZone that this DateFormat uses internally.
Method | Inherited From | Method | Inherited From |
---|---|---|---|
finalize() |
Object |
format(Object) |
Format |
getClass() |
Object |
notify() |
Object |
notifyAll() |
Object |
parseObject(String) |
Format |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Calendar, Cloneable, Date, FieldPosition, Format, Locale, NumberFormat, ParsePosition, String, StringBuffer, TimeZone
This HTML Help has been published using the chm2web software. |