java.text

Class DateFormat

public abstract class DateFormat extends Format implements Cloneable

UNKNOWN: October 25, 1998.

Nested Class Summary
static classDateFormat.Field
Field Summary
static intAM_PM_FIELD
Represents the position of the am/pm pattern character in the array of localized pattern characters.
protected Calendarcalendar
static intDATE_FIELD
Represents the position of the date or day of the month pattern character in the array of localized pattern characters.
static intDAY_OF_WEEK_FIELD
Represents the position of the day of the week pattern character in the array of localized pattern characters.
static intDAY_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 intDAY_OF_YEAR_FIELD
Represents the position of the day of the year pattern character in the array of localized pattern characters.
static intDEFAULT
static intERA_FIELD
Represents the position of the era pattern character in the array of localized pattern characters.
static intEXTENDED_YEAR_FIELD
Represents the position of the extended year pattern character in the array of localized pattern characters.
static intFULL
static intHOUR0_FIELD
Represents the position of the 12 hour pattern character in the array of localized pattern characters.
static intHOUR1_FIELD
Represents the position of the 12 hour pattern character in the array of localized pattern characters.
static intHOUR_OF_DAY0_FIELD
Represents the position of the 24 hour pattern character in the array of localized pattern characters.
static intHOUR_OF_DAY1_FIELD
Represents the position of the 24 hour pattern character in the array of localized pattern characters.
static intISO_YEAR_FIELD
Represents the position of the ISO year pattern character in the array of localized pattern characters.
static intLOCALIZED_DAY_OF_WEEK_FIELD
Represents the position of the localized day of the week pattern character in the array of localized pattern characters.
static intLONG
static intMEDIUM
static intMILLISECOND_FIELD
Represents the position of the millisecond pattern character in the array of localized pattern characters.
static intMILLISECOND_IN_DAY_FIELD
Represents the position of the millisecond in the day pattern character in the array of localized pattern characters.
static intMINUTE_FIELD
Represents the position of the minute pattern character in the array of localized pattern characters.
static intMODIFIED_JULIAN_DAY_FIELD
Represents the position of the modified Julian day pattern character in the array of localized pattern characters.
static intMONTH_FIELD
Represents the position of the month pattern character in the array of localized pattern characters.
protected NumberFormatnumberFormat
static intRFC822_TIMEZONE_FIELD
Represents the position of the RFC822 timezone pattern character in the array of localized pattern characters.
static intSECOND_FIELD
Represents the position of the second pattern character in the array of localized pattern characters.
static intSHORT
static intTIMEZONE_FIELD
Represents the position of the generic timezone pattern character in the array of localized pattern characters.
static intWEEK_OF_MONTH_FIELD
Represents the position of the week of the month pattern character in the array of localized pattern characters.
static intWEEK_OF_YEAR_FIELD
Represents the position of the week of the year pattern character in the array of localized pattern characters.
static intYEAR_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
Objectclone()
This method returns a copy of this object.
booleanequals(Object obj)
This method tests this object for equality against the specified object.
StringBufferformat(Object obj, StringBuffer buf, FieldPosition pos)
This method formats the specified Object into a date string and appends it to the specified StringBuffer.
Stringformat(Date date)
Formats the date argument according to the pattern specified.
abstract StringBufferformat(Date date, StringBuffer buf, FieldPosition pos)
This method formats a Date into a string and appends it to the specified StringBuffer.
static Locale[]getAvailableLocales()
This method returns a list of available locales supported by this class.
CalendargetCalendar()
This method returns the Calendar object being used by this object to parse/format datetimes.
static DateFormatgetDateInstance()
This method returns an instance of DateFormat that will format using the default formatting style for dates.
static DateFormatgetDateInstance(int style)
This method returns an instance of DateFormat that will format using the specified formatting style for dates.
static DateFormatgetDateInstance(int style, Locale loc)
This method returns an instance of DateFormat that will format using the specified formatting style for dates.
static DateFormatgetDateTimeInstance()
This method returns a new instance of DateFormat that formats both dates and times using the SHORT style.
static DateFormatgetDateTimeInstance(int dateStyle, int timeStyle)
This method returns a new instance of DateFormat that formats both dates and times using the DEFAULT style.
static DateFormatgetDateTimeInstance(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 DateFormatgetInstance()
This method returns a new instance of DateFormat that formats both dates and times using the SHORT style.
NumberFormatgetNumberFormat()
This method returns the NumberFormat object being used by this object to parse/format time values.
static DateFormatgetTimeInstance()
This method returns an instance of DateFormat that will format using the default formatting style for times.
static DateFormatgetTimeInstance(int style)
This method returns an instance of DateFormat that will format using the specified formatting style for times.
static DateFormatgetTimeInstance(int style, Locale loc)
This method returns an instance of DateFormat that will format using the specified formatting style for times.
TimeZonegetTimeZone()
This method returns the TimeZone object being used by this instance.
inthashCode()
This method returns a hash value for this object.
booleanisLenient()
This method indicates whether or not the parsing of date and time values should be done in a lenient value.
Dateparse(String source)
This method parses the specified date/time string.
abstract Dateparse(String source, ParsePosition pos)
This method parses the specified String into a Date.
ObjectparseObject(String source, ParsePosition pos)
This method is identical to parse(String, ParsePosition), but returns its result as an Object instead of a Date.
voidsetCalendar(Calendar calendar)
This method specified the Calendar that should be used by this object to parse/format datetimes.
voidsetLenient(boolean lenient)
This method specifies whether or not this object should be lenient in the syntax it accepts while parsing date/time values.
voidsetNumberFormat(NumberFormat numberFormat)
This method specifies the NumberFormat object that should be used by this object to parse/format times.
voidsetTimeZone(TimeZone timeZone)
This method sets the time zone that should be used by this object.

Field Detail

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'.

calendar

protected Calendar calendar

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'.

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'.

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'.

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'.

DEFAULT

public static final int DEFAULT

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'.

EXTENDED_YEAR_FIELD

public static final int EXTENDED_YEAR_FIELD
Represents the position of the extended year pattern character in the array of localized pattern characters. In the U.S. locale, this is 'u'. This is a GNU extension in accordance with the CLDR data used. This value modifies the year value, so as to incorporate the era. For example, in the Gregorian calendar system, the extended year is negative instead of being marked as BC.

FULL

public static final int FULL

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.

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.

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.

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.

ISO_YEAR_FIELD

public static final int ISO_YEAR_FIELD
Represents the position of the ISO year pattern character in the array of localized pattern characters. In the U.S. locale, this is 'Y'. This is a GNU extension in accordance with the CLDR data used. This value may differ from the normal year value.

LOCALIZED_DAY_OF_WEEK_FIELD

public static final int LOCALIZED_DAY_OF_WEEK_FIELD
Represents the position of the localized day of the week pattern character in the array of localized pattern characters. In the U.S. locale, this is 'e'. This is a GNU extension in accordance with the CLDR data used. This value only differs from the day of the week with numeric formatting, in which case the locale's first day of the week is used.

LONG

public static final int LONG

MEDIUM

public static final int MEDIUM

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'.

MILLISECOND_IN_DAY_FIELD

public static final int MILLISECOND_IN_DAY_FIELD
Represents the position of the millisecond in the day pattern character in the array of localized pattern characters. In the U.S. locale, this is 'A'. This is a GNU extension in accordance with the CLDR data used. This value represents all the time fields (excluding the time zone) numerically, giving the number of milliseconds into the day (e.g. 10 in the morning would be 10 * 60 * 60 * 1000). Any daylight savings offset also affects this value.

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'.

MODIFIED_JULIAN_DAY_FIELD

public static final int MODIFIED_JULIAN_DAY_FIELD
Represents the position of the modified Julian day pattern character in the array of localized pattern characters. In the U.S. locale, this is 'g'. This is a GNU extension in accordance with the CLDR data used. This value differs from the standard Julian day in that days are marked from midnight onwards rather than noon, and the local time zone affects the value. In simple terms, it can be thought of as all the date fields represented as a single number.

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'.

numberFormat

protected NumberFormat numberFormat

RFC822_TIMEZONE_FIELD

public static final int RFC822_TIMEZONE_FIELD
Represents the position of the RFC822 timezone pattern character in the array of localized pattern characters. In the U.S. locale, this is 'Z'. This is a GNU extension in accordance with the CLDR data used. The value is the offset of the current time from GMT e.g. -0500 would be five hours prior to GMT.

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'.

SHORT

public static final int SHORT

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'.

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'.

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'.

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'.

Constructor Detail

DateFormat

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

Method Detail

clone

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

Returns: A copy of this object.

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.

Parameters: obj The object to test for equality against.

Returns: true if the specified object is equal to this object, false otherwise.

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.

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.

Returns: A hash value for this 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)
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.

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.