java.text
Class DateFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
SimpleDateFormat

public abstract class DateFormat
extends Format
implements Cloneable

See Also:
Serialized Form

Nested Class Summary
static class DateFormat.Field
           
 
Field Summary
static int AM_PM_FIELD
          Represents the position of the am/pm pattern character in the array of localized pattern characters.
protected  Calendar calendar
           
static int DATE_FIELD
          Represents the position of the date or day of the month pattern character in the array of localized pattern characters.
static int DAY_OF_WEEK_FIELD
          Represents the position of the day of the week pattern character in the array of localized pattern characters.
static int DAY_OF_WEEK_IN_MONTH_FIELD
          Represents the position of the day of the week in the month pattern character in the array of localized pattern characters.
static int DAY_OF_YEAR_FIELD
          Represents the position of the day of the year pattern character in the array of localized pattern characters.
static int DEFAULT
           
static int ERA_FIELD
          Represents the position of the era pattern character in the array of localized pattern characters.
static int FULL
           
static int HOUR_OF_DAY0_FIELD
          Represents the position of the 24 hour pattern character in the array of localized pattern characters.
static int HOUR_OF_DAY1_FIELD
          Represents the position of the 24 hour pattern character in the array of localized pattern characters.
static int HOUR0_FIELD
          Represents the position of the 12 hour pattern character in the array of localized pattern characters.
static int HOUR1_FIELD
          Represents the position of the 12 hour pattern character in the array of localized pattern characters.
static int LONG
           
static int MEDIUM
           
static int MILLISECOND_FIELD
          Represents the position of the millisecond pattern character in the array of localized pattern characters.
static int MINUTE_FIELD
          Represents the position of the minute pattern character in the array of localized pattern characters.
static int MONTH_FIELD
          Represents the position of the month pattern character in the array of localized pattern characters.
protected  NumberFormat numberFormat
           
static int SECOND_FIELD
          Represents the position of the second pattern character in the array of localized pattern characters.
static int SHORT
           
static int TIMEZONE_FIELD
          Represents the position of the generic timezone pattern character in the array of localized pattern characters.
static int WEEK_OF_MONTH_FIELD
          Represents the position of the week of the month pattern character in the array of localized pattern characters.
static int WEEK_OF_YEAR_FIELD
          Represents the position of the week of the year pattern character in the array of localized pattern characters.
static int YEAR_FIELD
          Represents the position of the year pattern character in the array of localized pattern characters.
 
Constructor Summary
protected DateFormat()
          This method initializes a new instance of DateFormat.
 
Method Summary
 Object clone()
          This method returns a copy of this object.
 boolean equals(Object obj)
          This method tests this object for equality against the specified object.
 String format(Date date)
          Formats the date argument according to the pattern specified.
abstract  StringBuffer format(Date date, StringBuffer buf, FieldPosition pos)
          This method formats a Date into a string and appends it to the specified StringBuffer.
 StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos)
          This method formats the specified Object into a date string and appends it to the specified StringBuffer.
static Locale[] getAvailableLocales()
          This method returns a list of available locales supported by this class.
 Calendar getCalendar()
          This method returns the Calendar object being used by this object to parse/format datetimes.
static DateFormat getDateInstance()
          This method returns an instance of DateFormat that will format using the default formatting style for dates.
static DateFormat getDateInstance(int style)
          This method returns an instance of DateFormat that will format using the specified formatting style for dates.
static DateFormat getDateInstance(int style, Locale loc)
          This method returns an instance of DateFormat that will format using the specified formatting style for dates.
static DateFormat getDateTimeInstance()
          This method returns a new instance of DateFormat that formats both dates and times using the SHORT style.
static DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
          This method returns a new instance of DateFormat that formats both dates and times using the DEFAULT style.
static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale loc)
          This method returns a new instance of DateFormat that formats both dates and times using the specified styles.
static DateFormat getInstance()
          This method returns a new instance of DateFormat that formats both dates and times using the SHORT style.
 NumberFormat getNumberFormat()
          This method returns the NumberFormat object being used by this object to parse/format time values.
static DateFormat getTimeInstance()
          This method returns an instance of DateFormat that will format using the default formatting style for times.
static DateFormat getTimeInstance(int style)
          This method returns an instance of DateFormat that will format using the specified formatting style for times.
static DateFormat getTimeInstance(int style, Locale loc)
          This method returns an instance of DateFormat that will format using the specified formatting style for times.
 TimeZone getTimeZone()
          This method returns the TimeZone object being used by this instance.
 int hashCode()
          This method returns a hash value for this object.
 boolean isLenient()
          This method indicates whether or not the parsing of date and time values should be done in a lenient value.
 Date parse(String source)
          This method parses the specified date/time string.
abstract  Date parse(String source, ParsePosition pos)
          This method parses the specified String into a Date.
 Object parseObject(String source, ParsePosition pos)
          This method is identical to parse(String, ParsePosition), but returns its result as an Object instead of a Date.
 void setCalendar(Calendar calendar)
          This method specified the Calendar that should be used by this object to parse/format datetimes.
 void setLenient(boolean lenient)
          This method specifies whether or not this object should be lenient in the syntax it accepts while parsing date/time values.
 void setNumberFormat(NumberFormat numberFormat)
          This method specifies the NumberFormat object that should be used by this object to parse/format times.
 void setTimeZone(TimeZone timeZone)
          This method sets the time zone that should be used by this object.
 
Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

calendar

protected Calendar calendar

numberFormat

protected NumberFormat numberFormat

FULL

public static final int FULL
See Also:
Constant Field Values

LONG

public static final int LONG
See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
See Also:
Constant Field Values

SHORT

public static final int SHORT
See Also:
Constant Field Values

DEFAULT

public static final int DEFAULT
See Also:
Constant Field Values

ERA_FIELD

public static final int ERA_FIELD
Represents the position of the era pattern character in the array of localized pattern characters. For example, 'AD' is an era used in the Gregorian calendar system. In the U.S. locale, this is 'G'.

See Also:
Constant Field Values

YEAR_FIELD

public static final int YEAR_FIELD
Represents the position of the year pattern character in the array of localized pattern characters. In the U.S. locale, this is 'y'.

See Also:
Constant Field Values

MONTH_FIELD

public static final int MONTH_FIELD
Represents the position of the month pattern character in the array of localized pattern characters. In the U.S. locale, this is 'M'.

See Also:
Constant Field Values

DATE_FIELD

public static final int DATE_FIELD
Represents the position of the date or day of the month pattern character in the array of localized pattern characters. In the U.S. locale, this is 'd'.

See Also:
Constant Field Values

HOUR_OF_DAY1_FIELD

public static final int HOUR_OF_DAY1_FIELD
Represents the position of the 24 hour pattern character in the array of localized pattern characters. In the U.S. locale, this is 'k'. This field numbers hours from 1 to 24.

See Also:
Constant Field Values

HOUR_OF_DAY0_FIELD

public static final int HOUR_OF_DAY0_FIELD
Represents the position of the 24 hour pattern character in the array of localized pattern characters. In the U.S. locale, this is 'H'. This field numbers hours from 0 to 23.

See Also:
Constant Field Values

MINUTE_FIELD

public static final int MINUTE_FIELD
Represents the position of the minute pattern character in the array of localized pattern characters. In the U.S. locale, this is 'm'.

See Also:
Constant Field Values

SECOND_FIELD

public static final int SECOND_FIELD
Represents the position of the second pattern character in the array of localized pattern characters. In the U.S. locale, this is 's'.

See Also:
Constant Field Values

MILLISECOND_FIELD

public static final int MILLISECOND_FIELD
Represents the position of the millisecond pattern character in the array of localized pattern characters. In the U.S. locale, this is 'S'.

See Also:
Constant Field Values

DAY_OF_WEEK_FIELD

public static final int DAY_OF_WEEK_FIELD
Represents the position of the day of the week pattern character in the array of localized pattern characters. In the U.S. locale, this is 'E'.

See Also:
Constant Field Values

DAY_OF_YEAR_FIELD

public static final int DAY_OF_YEAR_FIELD
Represents the position of the day of the year pattern character in the array of localized pattern characters. In the U.S. locale, this is 'D'.

See Also:
Constant Field Values

DAY_OF_WEEK_IN_MONTH_FIELD

public static final int DAY_OF_WEEK_IN_MONTH_FIELD
Represents the position of the day of the week in the month pattern character in the array of localized pattern characters. In the U.S. locale, this is 'F'.

See Also:
Constant Field Values

WEEK_OF_YEAR_FIELD

public static final int WEEK_OF_YEAR_FIELD
Represents the position of the week of the year pattern character in the array of localized pattern characters. In the U.S. locale, this is 'w'.

See Also:
Constant Field Values

WEEK_OF_MONTH_FIELD

public static final int WEEK_OF_MONTH_FIELD
Represents the position of the week of the month pattern character in the array of localized pattern characters. In the U.S. locale, this is 'W'.

See Also:
Constant Field Values

AM_PM_FIELD

public static final int AM_PM_FIELD
Represents the position of the am/pm pattern character in the array of localized pattern characters. In the U.S. locale, this is 'a'.

See Also:
Constant Field Values

HOUR1_FIELD

public static final int HOUR1_FIELD
Represents the position of the 12 hour pattern character in the array of localized pattern characters. In the U.S. locale, this is 'h'. This field numbers hours from 1 to 12.

See Also:
Constant Field Values

HOUR0_FIELD

public static final int HOUR0_FIELD
Represents the position of the 12 hour pattern character in the array of localized pattern characters. In the U.S. locale, this is 'K'. This field numbers hours from 0 to 11.

See Also:
Constant Field Values

TIMEZONE_FIELD

public static final int TIMEZONE_FIELD
Represents the position of the generic timezone pattern character in the array of localized pattern characters. In the U.S. locale, this is 'z'.

See Also:
Constant Field Values
Constructor Detail

DateFormat

protected DateFormat()
This method initializes a new instance of DateFormat.

Method Detail

equals

public boolean equals(Object obj)
This method tests this object for equality against the specified object. The two objects will be considered equal if an only if the specified object:

Note that not all properties of the Calendar are relevant for a DateFormat. For formatting only the fact whether or not the TimeZone has the same rules and whether the calendar is lenient and has the same week rules is compared for this implementation of equals. Other properties of the Calendar (such as the time) are not taken into account.

Overrides:
equals in class Object
Parameters:
obj - The object to test for equality against.
Returns:
true if the specified object is equal to this object, false otherwise.
See Also:
Object.hashCode()

clone

public Object clone()
This method returns a copy of this object.

Overrides:
clone in class Format
Returns:
A copy of this object.
See Also:
Cloneable

format

public final StringBuffer format(Object obj,
                                 StringBuffer buf,
                                 FieldPosition pos)
This method formats the specified Object into a date string and appends it to the specified StringBuffer. The specified object must be an instance of Number or Date or an IllegalArgumentException will be thrown.

Specified by:
format in class Format
Parameters:
obj - The Object to format.
buf - The StringBuffer to append the resultant String to.
pos - Is updated to the start and end index of the specified field.
Returns:
The StringBuffer supplied on input, with the formatted date/time appended.

format

public final String format(Date date)
Formats the date argument according to the pattern specified.

Parameters:
date - The formatted date.

format

public abstract StringBuffer format(Date date,
                                    StringBuffer buf,
                                    FieldPosition pos)
This method formats a Date into a string and appends it to the specified StringBuffer.

Parameters:
date - The Date value to format.
buf - The StringBuffer to append the resultant String to.
pos - Is updated to the start and end index of the specified field.
Returns:
The StringBuffer supplied on input, with the formatted date/time appended.

getAvailableLocales

public static Locale[] getAvailableLocales()
This method returns a list of available locales supported by this class.


getCalendar

public Calendar getCalendar()
This method returns the Calendar object being used by this object to parse/format datetimes.

Returns:
The Calendar being used by this object.
See Also:
Calendar

getDateInstance

public static final DateFormat getDateInstance()
This method returns an instance of DateFormat that will format using the default formatting style for dates.

Returns:
A new DateFormat instance.

getDateInstance

public static final DateFormat getDateInstance(int style)
This method returns an instance of DateFormat that will format using the specified formatting style for dates.

Parameters:
style - The type of formatting to perform.
Returns:
A new DateFormat instance.

getDateInstance

public static final DateFormat getDateInstance(int style,
                                               Locale loc)
This method returns an instance of DateFormat that will format using the specified formatting style for dates. The specified localed will be used in place of the default.

Parameters:
style - The type of formatting to perform.
loc - The desired locale.
Returns:
A new DateFormat instance.

getDateTimeInstance

public static final DateFormat getDateTimeInstance()
This method returns a new instance of DateFormat that formats both dates and times using the SHORT style.

Returns:
A new DateFormatinstance.

getDateTimeInstance

public static final DateFormat getDateTimeInstance(int dateStyle,
                                                   int timeStyle)
This method returns a new instance of DateFormat that formats both dates and times using the DEFAULT style.

Returns:
A new DateFormatinstance.

getDateTimeInstance

public static final DateFormat getDateTimeInstance(int dateStyle,
                                                   int timeStyle,
                                                   Locale loc)
This method returns a new instance of DateFormat that formats both dates and times using the specified styles.

Parameters:
dateStyle - The desired style for date formatting.
timeStyle - The desired style for time formatting
Returns:
A new DateFormatinstance.

getInstance

public static final DateFormat getInstance()
This method returns a new instance of DateFormat that formats both dates and times using the SHORT style.

Returns:
A new DateFormatinstance.

getNumberFormat

public NumberFormat getNumberFormat()
This method returns the NumberFormat object being used by this object to parse/format time values.

Returns:
The NumberFormat in use by this object.

getTimeInstance

public static final DateFormat getTimeInstance()
This method returns an instance of DateFormat that will format using the default formatting style for times.

Returns:
A new DateFormat instance.

getTimeInstance

public static final DateFormat getTimeInstance(int style)
This method returns an instance of DateFormat that will format using the specified formatting style for times.

Parameters:
style - The type of formatting to perform.
Returns:
A new DateFormat instance.

getTimeInstance

public static final DateFormat getTimeInstance(int style,
                                               Locale loc)
This method returns an instance of DateFormat that will format using the specified formatting style for times. The specified localed will be used in place of the default.

Parameters:
style - The type of formatting to perform.
loc - The desired locale.
Returns:
A new DateFormat instance.

getTimeZone

public TimeZone getTimeZone()
This method returns the TimeZone object being used by this instance.

Returns:
The time zone in use.

hashCode

public int hashCode()
This method returns a hash value for this object.

Overrides:
hashCode in class Object
Returns:
A hash value for this object.
See Also:
Object.equals(Object), System.identityHashCode(Object)

isLenient

public boolean isLenient()
This method indicates whether or not the parsing of date and time values should be done in a lenient value.

Returns:
true if date/time parsing is lenient, false otherwise.

parse

public Date parse(String source)
           throws ParseException
This method parses the specified date/time string.

Parameters:
source - The string to parse.
Returns:
The resultant date.
Throws:
ParseException - If the specified string cannot be parsed.

parse

public abstract Date parse(String source,
                           ParsePosition pos)
This method parses the specified String into a Date. The pos argument contains the starting parse position on method entry and the ending parse position on method exit.

Parameters:
source - The string to parse.
pos - The starting parse position in entry, the ending parse position on exit.
Returns:
The parsed date, or null if the string cannot be parsed.

parseObject

public Object parseObject(String source,
                          ParsePosition pos)
This method is identical to parse(String, ParsePosition), but returns its result as an Object instead of a Date.

Specified by:
parseObject in class Format
Parameters:
source - The string to parse.
pos - The starting parse position in entry, the ending parse position on exit.
Returns:
The parsed date, or null if the string cannot be parsed.

setCalendar

public void setCalendar(Calendar calendar)
This method specified the Calendar that should be used by this object to parse/format datetimes.

Parameters:
calendar - The new Calendar for this object.
See Also:
Calendar

setLenient

public void setLenient(boolean lenient)
This method specifies whether or not this object should be lenient in the syntax it accepts while parsing date/time values.

Parameters:
lenient - true if parsing should be lenient, false otherwise.

setNumberFormat

public void setNumberFormat(NumberFormat numberFormat)
This method specifies the NumberFormat object that should be used by this object to parse/format times.

Parameters:
numberFormat - The NumberFormat in use by this object.

setTimeZone

public void setTimeZone(TimeZone timeZone)
This method sets the time zone that should be used by this object.

Parameters:
timeZone - The new time zone.