java.text
public
abstract
class
java.text.DateFormat
DateFormat is the abstract superclass of formats which format and parse
Dates.
Nested Classes
DateFormat.Field |
The instances of this inner class are used as attribute keys and values
in AttributedCharacterIterator that
SimpleDateFormat.formatToCharacterIterator() method returns. |
Known Direct Subclasses
SimpleDateFormat |
SimpleDateFormat is used to format and parse Gregorian calendar dates and
times based on a pattern of date and time fields. |
Summary
Constants
Fields
Protected Constructors
Public Methods
|
|
|
|
|
Object |
clone() |
|
|
|
|
|
boolean |
equals(Object object) |
|
|
final |
|
|
StringBuffer |
format(Object object, StringBuffer buffer, FieldPosition field) |
|
|
final |
|
|
String |
format(Date date) |
abstract |
|
|
|
|
StringBuffer |
format(Date date, StringBuffer buffer, FieldPosition field) |
|
|
|
static |
|
Locale[] |
getAvailableLocales() |
|
|
|
|
|
Calendar |
getCalendar() |
|
|
final |
static |
|
DateFormat |
getDateInstance(int style, Locale locale) |
|
|
final |
static |
|
DateFormat |
getDateInstance() |
|
|
final |
static |
|
DateFormat |
getDateInstance(int style) |
|
|
final |
static |
|
DateFormat |
getDateTimeInstance(int dateStyle, int timeStyle) |
|
|
final |
static |
|
DateFormat |
getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) |
|
|
final |
static |
|
DateFormat |
getDateTimeInstance() |
|
|
final |
static |
|
DateFormat |
getInstance() |
|
|
|
|
|
NumberFormat |
getNumberFormat() |
|
|
final |
static |
|
DateFormat |
getTimeInstance(int style) |
|
|
final |
static |
|
DateFormat |
getTimeInstance() |
|
|
final |
static |
|
DateFormat |
getTimeInstance(int style, Locale locale) |
|
|
|
|
|
TimeZone |
getTimeZone() |
|
|
|
|
|
int |
hashCode() |
|
|
|
|
|
boolean |
isLenient() |
|
|
|
|
|
Date |
parse(String string) |
abstract |
|
|
|
|
Date |
parse(String string, ParsePosition position) |
|
|
|
|
|
Object |
parseObject(String string, ParsePosition position) |
|
|
|
|
|
void |
setCalendar(Calendar cal) |
|
|
|
|
|
void |
setLenient(boolean value) |
|
|
|
|
|
void |
setNumberFormat(NumberFormat format) |
|
|
|
|
|
void |
setTimeZone(TimeZone timezone) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
AM_PM_FIELD
Field constant.
Constant Value:
14
(0x0000000e)
public
static
final
int
DATE_FIELD
Field constant.
Constant Value:
3
(0x00000003)
public
static
final
int
DAY_OF_WEEK_FIELD
Field constant.
Constant Value:
9
(0x00000009)
public
static
final
int
DAY_OF_WEEK_IN_MONTH_FIELD
Field constant.
Constant Value:
11
(0x0000000b)
public
static
final
int
DAY_OF_YEAR_FIELD
Field constant.
Constant Value:
10
(0x0000000a)
public
static
final
int
DEFAULT
Format style constant.
Constant Value:
2
(0x00000002)
public
static
final
int
ERA_FIELD
Field constant.
Constant Value:
0
(0x00000000)
public
static
final
int
FULL
Format style constant.
Constant Value:
0
(0x00000000)
public
static
final
int
HOUR0_FIELD
Field constant.
Constant Value:
16
(0x00000010)
public
static
final
int
HOUR1_FIELD
Field constant.
Constant Value:
15
(0x0000000f)
public
static
final
int
HOUR_OF_DAY0_FIELD
Field constant.
Constant Value:
5
(0x00000005)
public
static
final
int
HOUR_OF_DAY1_FIELD
Field constant.
Constant Value:
4
(0x00000004)
public
static
final
int
LONG
Format style constant.
Constant Value:
1
(0x00000001)
public
static
final
int
MEDIUM
Format style constant.
Constant Value:
2
(0x00000002)
public
static
final
int
MILLISECOND_FIELD
Field constant.
Constant Value:
8
(0x00000008)
public
static
final
int
MINUTE_FIELD
Field constant.
Constant Value:
6
(0x00000006)
public
static
final
int
MONTH_FIELD
Field constant.
Constant Value:
2
(0x00000002)
public
static
final
int
SECOND_FIELD
Field constant.
Constant Value:
7
(0x00000007)
public
static
final
int
SHORT
Format style constant.
Constant Value:
3
(0x00000003)
public
static
final
int
TIMEZONE_FIELD
Field constant.
Constant Value:
17
(0x00000011)
public
static
final
int
WEEK_OF_MONTH_FIELD
Field constant.
Constant Value:
13
(0x0000000d)
public
static
final
int
WEEK_OF_YEAR_FIELD
Field constant.
Constant Value:
12
(0x0000000c)
public
static
final
int
YEAR_FIELD
Field constant.
Constant Value:
1
(0x00000001)
Fields
protected
Calendar
calendar
The calendar that this DateFormat
uses to format a number
representing a date.
The number format used to format a number.
Protected Constructors
protected
DateFormat()
Constructs a new instance of DateFormat.
Public Methods
public
Object
clone()
Returns a new instance of DateFormat with the same properties.
Returns
- a shallow copy of this DateFormat
public
boolean
equals(Object object)
Compares the specified object to this DateFormat and answer if they are
equal. The object must be an instance of DateFormat with the same
properties.
Parameters
object
| the object to compare with this object |
Returns
- true if the specified object is equal to this DateFormat, false
otherwise
Formats the specified object into the specified StringBuffer using the
rules of this DateFormat. If the field specified by the FieldPosition is
formatted, set the begin and end index of the formatted field in the
FieldPosition.
Parameters
object
| the object to format, must be a Date or a Number. If the
object is a Number, a Date is constructed using the
longValue() of the Number. |
buffer
| the StringBuffer |
field
| the FieldPosition |
Returns
- the StringBuffer parameter
buffer
public
final
String
format(Date date)
Formats the specified Date using the rules of this DateFormat.
Formats the specified Date into the specified StringBuffer using the
rules of this DateFormat. If the field specified by the FieldPosition is
formatted, set the begin and end index of the formatted field in the
FieldPosition.
Parameters
date
| the Date to format |
buffer
| the StringBuffer |
field
| the FieldPosition |
Returns
- the StringBuffer parameter
buffer
public
static
Locale[]
getAvailableLocales()
Gets the list of installed Locales which support DateFormat.
public
Calendar
getCalendar()
Returns the Calendar used by this DateFormat.
public
static
final
DateFormat
getDateInstance(int style, Locale locale)
Returns a DateFormat instance for formatting and parsing dates in the
specified style for the specified Locale.
Parameters
style
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
locale
| the Locale |
public
static
final
DateFormat
getDateInstance()
Returns a DateFormat instance for formatting and parsing dates in the
DEFAULT style for the default Locale.
public
static
final
DateFormat
getDateInstance(int style)
Returns a DateFormat instance for formatting and parsing dates in the
specified style for the default Locale.
Parameters
style
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
public
static
final
DateFormat
getDateTimeInstance(int dateStyle, int timeStyle)
Returns a
DateFormat
instance for the formatting and
parsing of both dates and times in the manner appropriate to the default
Locale.
Parameters
dateStyle
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
timeStyle
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
public
static
final
DateFormat
getDateTimeInstance(int dateStyle, int timeStyle, Locale locale)
Returns a DateFormat instance for formatting and parsing dates and times
in the specified styles for the specified Locale.
Parameters
dateStyle
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
timeStyle
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
locale
| the Locale |
public
static
final
DateFormat
getDateTimeInstance()
Returns a DateFormat instance for formatting and parsing dates and times
in the DEFAULT style for the default Locale.
public
static
final
DateFormat
getInstance()
Returns a DateFormat instance for formatting and parsing dates and times
in the SHORT style for the default Locale.
public
NumberFormat
getNumberFormat()
Returns the NumberFormat used by this DateFormat.
public
static
final
DateFormat
getTimeInstance(int style)
Returns a DateFormat instance for formatting and parsing times in the
specified style for the default Locale.
Parameters
style
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
public
static
final
DateFormat
getTimeInstance()
Returns a DateFormat instance for formatting and parsing times in the
DEFAULT style for the default Locale.
public
static
final
DateFormat
getTimeInstance(int style, Locale locale)
Returns a DateFormat instance for formatting and parsing times in the
specified style for the specified Locale.
Parameters
style
| one of SHORT, MEDIUM, LONG, FULL, or DEFAULT |
locale
| the Locale |
public
TimeZone
getTimeZone()
Returns the TimeZone of the Calendar used by this DateFormat.
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
boolean
isLenient()
Returns if the Calendar used by this DateFormat is lenient.
Returns
- true when the Calendar is lenient, false otherwise
public
Date
parse(String string)
Parse a Date from the specified String using the rules of this
DateFormat.
Parameters
string
| the String to parse |
Returns
- the Date resulting from the parse
Parse a Date from the specified String starting at the index specified by
the ParsePosition. If the string is successfully parsed, the index of the
ParsePosition is updated to the index following the parsed text.
Parameters
string
| the String to parse |
position
| the ParsePosition, updated on return with the index following
the parsed text, or on error the index is unchanged and the
error index is set to the index where the error occurred |
Returns
- the Date resulting from the parse, or null if there is an error
Parse a Date from the specified String starting at the index specified by
the ParsePosition. If the string is successfully parsed, the index of the
ParsePosition is updated to the index following the parsed text.
Parameters
string
| the String to parse |
position
| the ParsePosition, updated on return with the index following
the parsed text, or on error the index is unchanged and the
error index is set to the index where the error occurred |
Returns
- the Date resulting from the parse, or null if there is an error
public
void
setCalendar(Calendar cal)
Sets the Calendar used by this DateFormat.
public
void
setLenient(boolean value)
Sets if the Calendar used by this DateFormat is lenient.
Parameters
value
| true to set the Calendar to be lenient, false otherwise
|
public
void
setNumberFormat(NumberFormat format)
Sets the NumberFormat used by this DateFormat.
public
void
setTimeZone(TimeZone timezone)
Sets the TimeZone of the Calendar used by this DateFormat.