java.text
Class DateFormat
- Cloneable, Serializable
static int | AM_PM_FIELD - Represents the position of the am/pm
pattern character in the array of
localized pattern characters.
|
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 | 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 | 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 | 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.
|
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.
|
protected Calendar | calendar
|
protected NumberFormat | numberFormat
|
DateFormat() - This method initializes a new instance of
DateFormat .
|
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.
|
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 .
|
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 .
|
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.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
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'.
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'.
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.
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'.
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'.
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'.
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'.
DateFormat
protected DateFormat()
This method initializes a new instance of DateFormat
.
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:
- Is not
null
. - Is an instance of
DateFormat
. - Has equal numberFormat field as this object.
- Has equal (Calendar) TimeZone rules as this object.
- Has equal (Calendar) isLenient results.
- Has equal Calendar first day of week and minimal days in week
values.
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.
- equals in interface Object
obj
- The object to test for equality against.
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.
- format in interface Format
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.
- 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.
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
.
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.
- 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.
- The
Calendar
being used by this object.
getDateInstance
public static final DateFormat getDateInstance()
This method returns an instance of DateFormat
that will
format using the default formatting style for dates.
- 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.
style
- The type of formatting to perform.
- 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.
style
- The type of formatting to perform.loc
- The desired locale.
- 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.
- A new
DateFormat
instance.
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.
- A new
DateFormat
instance.
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.
dateStyle
- The desired style for date formatting.timeStyle
- The desired style for time formatting
- A new
DateFormat
instance.
getInstance
public static final DateFormat getInstance()
This method returns a new instance of DateFormat
that
formats both dates and times using the SHORT
style.
- A new
DateFormat
instance.
getNumberFormat
public NumberFormat getNumberFormat()
This method returns the NumberFormat
object being used
by this object to parse/format time values.
- 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.
- 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.
style
- The type of formatting to perform.
- 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.
style
- The type of formatting to perform.loc
- The desired locale.
- A new
DateFormat
instance.
getTimeZone
public TimeZone getTimeZone()
This method returns the TimeZone
object being used by
this instance.
hashCode
public int hashCode()
This method returns a hash value for this object.
- hashCode in interface Object
- 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.
true
if date/time parsing is lenient,
false
otherwise.
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.
source
- The string to parse.pos
- The starting parse position in entry, the ending parse
position on exit.
- 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
.
- parseObject in interface Format
source
- The string to parse.pos
- The starting parse position in entry, the ending parse
position on exit.
- 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.
calendar
- The new Calendar
for this object.
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.
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.
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.
timeZone
- The new time zone.
DateFormat.java -- Class for formatting/parsing date/times
Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.