public abstract class DateFormat extends Format implements Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
DateFormat.Field |
Modifier and Type | Field and Description |
---|---|
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.
|
Modifier | Constructor and Description |
---|---|
protected |
DateFormat()
This method initializes a new instance of
DateFormat . |
Modifier and Type | Method and Description |
---|---|
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.
|
format, formatToCharacterIterator, parseObject
protected NumberFormat numberFormat
public static final int FULL
public static final int LONG
public static final int MEDIUM
public static final int SHORT
public static final int DEFAULT
public static final int ERA_FIELD
public static final int YEAR_FIELD
public static final int MONTH_FIELD
public static final int DATE_FIELD
public static final int HOUR_OF_DAY1_FIELD
public static final int HOUR_OF_DAY0_FIELD
public static final int MINUTE_FIELD
public static final int SECOND_FIELD
public static final int MILLISECOND_FIELD
public static final int DAY_OF_WEEK_FIELD
public static final int DAY_OF_YEAR_FIELD
public static final int DAY_OF_WEEK_IN_MONTH_FIELD
public static final int WEEK_OF_YEAR_FIELD
public static final int WEEK_OF_MONTH_FIELD
public static final int AM_PM_FIELD
public static final int HOUR1_FIELD
public static final int HOUR0_FIELD
public static final int TIMEZONE_FIELD
protected DateFormat()
DateFormat
.public boolean equals(Object obj)
null
.DateFormat
.equals
in class Object
obj
- The object to test for equality against.true
if the specified object is equal to this object,
false
otherwise.Object.hashCode()
public final StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos)
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.public final String format(Date date)
date
- The formatted date.public abstract StringBuffer format(Date date, StringBuffer buf, FieldPosition pos)
Date
into a string and appends it
to the specified StringBuffer
.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.StringBuffer
supplied on input, with the
formatted date/time appended.public static Locale[] getAvailableLocales()
public Calendar getCalendar()
Calendar
object being used by
this object to parse/format datetimes.Calendar
being used by this object.Calendar
public static final DateFormat getDateInstance()
DateFormat
that will
format using the default formatting style for dates.DateFormat
instance.public static final DateFormat getDateInstance(int style)
DateFormat
that will
format using the specified formatting style for dates.style
- The type of formatting to perform.DateFormat
instance.public static final DateFormat getDateInstance(int style, Locale loc)
DateFormat
that will
format using the specified formatting style for dates. The specified
localed will be used in place of the default.style
- The type of formatting to perform.loc
- The desired locale.DateFormat
instance.public static final DateFormat getDateTimeInstance()
DateFormat
that
formats both dates and times using the SHORT
style.DateFormat
instance.public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
DateFormat
that
formats both dates and times using the DEFAULT
style.DateFormat
instance.public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale loc)
DateFormat
that
formats both dates and times using the specified styles.dateStyle
- The desired style for date formatting.timeStyle
- The desired style for time formattingDateFormat
instance.public static final DateFormat getInstance()
DateFormat
that
formats both dates and times using the SHORT
style.DateFormat
instance.public NumberFormat getNumberFormat()
NumberFormat
object being used
by this object to parse/format time values.NumberFormat
in use by this object.public static final DateFormat getTimeInstance()
DateFormat
that will
format using the default formatting style for times.DateFormat
instance.public static final DateFormat getTimeInstance(int style)
DateFormat
that will
format using the specified formatting style for times.style
- The type of formatting to perform.DateFormat
instance.public static final DateFormat getTimeInstance(int style, Locale loc)
DateFormat
that will
format using the specified formatting style for times. The specified
localed will be used in place of the default.style
- The type of formatting to perform.loc
- The desired locale.DateFormat
instance.public TimeZone getTimeZone()
TimeZone
object being used by
this instance.public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean isLenient()
true
if date/time parsing is lenient,
false
otherwise.public Date parse(String source) throws ParseException
source
- The string to parse.ParseException
- If the specified string cannot be parsed.public abstract Date parse(String source, ParsePosition pos)
String
into a
Date
. The pos
argument contains the
starting parse position on method entry and the ending parse
position on method exit.source
- The string to parse.pos
- The starting parse position in entry, the ending parse
position on exit.null
if the string cannot
be parsed.public Object parseObject(String source, ParsePosition pos)
parse(String, ParsePosition)
,
but returns its result as an Object
instead of a
Date
.parseObject
in class Format
source
- The string to parse.pos
- The starting parse position in entry, the ending parse
position on exit.null
if the string cannot
be parsed.public void setCalendar(Calendar calendar)
Calendar
that should be used
by this object to parse/format datetimes.calendar
- The new Calendar
for this object.Calendar
public void setLenient(boolean lenient)
lenient
- true
if parsing should be lenient,
false
otherwise.public void setNumberFormat(NumberFormat numberFormat)
NumberFormat
object that should
be used by this object to parse/format times.numberFormat
- The NumberFormat
in use by this object.public void setTimeZone(TimeZone timeZone)
timeZone
- The new time zone.