加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090217133118/http://developer.android.com:80/reference/java/text/DateFormat.html
public abstract class

DateFormat

extends Format
java.lang.Object
   ↳ java.text.Format
     ↳ java.text.DateFormat
Known Direct Subclasses

Class Overview

DateFormat is the abstract superclass of formats which format and parse Dates.

Summary

Nested Classes
public abstract class DateFormat.Field The instances of this inner class are used as attribute keys and values in AttributedCharacterIterator that SimpleDateFormat.formatToCharacterIterator() method returns. 
Constants
int AM_PM_FIELD Field constant.
int DATE_FIELD Field constant.
int DAY_OF_WEEK_FIELD Field constant.
int DAY_OF_WEEK_IN_MONTH_FIELD Field constant.
int DAY_OF_YEAR_FIELD Field constant.
int DEFAULT Format style constant.
int ERA_FIELD Field constant.
int FULL Format style constant.
int HOUR0_FIELD Field constant.
int HOUR1_FIELD Field constant.
int HOUR_OF_DAY0_FIELD Field constant.
int HOUR_OF_DAY1_FIELD Field constant.
int LONG Format style constant.
int MEDIUM Format style constant.
int MILLISECOND_FIELD Field constant.
int MINUTE_FIELD Field constant.
int MONTH_FIELD Field constant.
int SECOND_FIELD Field constant.
int SHORT Format style constant.
int TIMEZONE_FIELD Field constant.
int WEEK_OF_MONTH_FIELD Field constant.
int WEEK_OF_YEAR_FIELD Field constant.
int YEAR_FIELD Field constant.
Fields
protected Calendar calendar The calendar that this DateFormat uses to format a number representing a date.
protected NumberFormat numberFormat The number format used to format a number.
Protected Constructors
DateFormat()
Constructs a new instance of DateFormat.
Public Methods
Object clone()
Returns a new instance of DateFormat with the same properties.
boolean equals(Object object)
Compares the specified object to this DateFormat and answer if they are equal.
final StringBuffer format(Object object, StringBuffer buffer, FieldPosition field)
Formats the specified object into the specified StringBuffer using the rules of this DateFormat.
final String format(Date date)
Formats the specified Date using the rules of this DateFormat.
abstract StringBuffer format(Date date, StringBuffer buffer, FieldPosition field)
Formats the specified Date into the specified StringBuffer using the rules of this DateFormat.
static Locale[] getAvailableLocales()
Gets the list of installed Locales which support DateFormat.
Calendar getCalendar()
Returns the Calendar used by this DateFormat.
final static DateFormat getDateInstance(int style, Locale locale)
Returns a DateFormat instance for formatting and parsing dates in the specified style for the specified Locale.
final static DateFormat getDateInstance()
Returns a DateFormat instance for formatting and parsing dates in the DEFAULT style for the default Locale.
final static DateFormat getDateInstance(int style)
Returns a DateFormat instance for formatting and parsing dates in the specified style for the default Locale.
final static 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.
final static 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.
final static DateFormat getDateTimeInstance()
Returns a DateFormat instance for formatting and parsing dates and times in the DEFAULT style for the default Locale.
final static DateFormat getInstance()
Returns a DateFormat instance for formatting and parsing dates and times in the SHORT style for the default Locale.
NumberFormat getNumberFormat()
Returns the NumberFormat used by this DateFormat.
final static DateFormat getTimeInstance(int style)
Returns a DateFormat instance for formatting and parsing times in the specified style for the default Locale.
final static DateFormat getTimeInstance()
Returns a DateFormat instance for formatting and parsing times in the DEFAULT style for the default Locale.
final static DateFormat getTimeInstance(int style, Locale locale)
Returns a DateFormat instance for formatting and parsing times in the specified style for the specified Locale.
TimeZone getTimeZone()
Returns the TimeZone of the Calendar used by this DateFormat.
int hashCode()
Returns an integer hash code for the receiver.
boolean isLenient()
Returns if the Calendar used by this DateFormat is lenient.
Date parse(String string)
Parse a Date from the specified String using the rules of this DateFormat.
abstract Date parse(String string, ParsePosition position)
Parse a Date from the specified String starting at the index specified by the ParsePosition.
Object parseObject(String string, ParsePosition position)
Parse a Date from the specified String starting at the index specified by the ParsePosition.
void setCalendar(Calendar cal)
Sets the Calendar used by this DateFormat.
void setLenient(boolean value)
Sets if the Calendar used by this DateFormat is lenient.
void setNumberFormat(NumberFormat format)
Sets the NumberFormat used by this DateFormat.
void setTimeZone(TimeZone timezone)
Sets the TimeZone of the Calendar used by this DateFormat.
[Expand]
Inherited Methods
From class java.text.Format
From class java.lang.Object

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.

protected NumberFormat numberFormat

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
See Also

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
See Also

public final StringBuffer format (Object object, StringBuffer buffer, FieldPosition field)

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
Throws
IllegalArgumentException when the object is not a Date or a Number

public final String format (Date date)

Formats the specified Date using the rules of this DateFormat.

Parameters
date the Date to format
Returns
  • the formatted String

public abstract StringBuffer format (Date date, StringBuffer buffer, FieldPosition field)

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.

Returns
  • an array of Locale

public Calendar getCalendar ()

Returns the Calendar used by this DateFormat.

Returns
  • a Calendar

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
Returns
  • a DateFormat

public static final DateFormat getDateInstance ()

Returns a DateFormat instance for formatting and parsing dates in the DEFAULT style for the default Locale.

Returns
  • a DateFormat

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
Returns
  • a DateFormat

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
Returns
  • a DateFormat

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
Returns
  • a DateFormat

public static final DateFormat getDateTimeInstance ()

Returns a DateFormat instance for formatting and parsing dates and times in the DEFAULT style for the default Locale.

Returns
  • a DateFormat

public static final DateFormat getInstance ()

Returns a DateFormat instance for formatting and parsing dates and times in the SHORT style for the default Locale.

Returns
  • a DateFormat

public NumberFormat getNumberFormat ()

Returns the NumberFormat used by this DateFormat.

Returns
  • a NumberFormat

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
Returns
  • a DateFormat

public static final DateFormat getTimeInstance ()

Returns a DateFormat instance for formatting and parsing times in the DEFAULT style for the default Locale.

Returns
  • a DateFormat

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
Returns
  • a DateFormat

public TimeZone getTimeZone ()

Returns the TimeZone of the Calendar used by this DateFormat.

Returns
  • a TimeZone

public int hashCode ()

Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Returns
  • the receiver's hash
See Also

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
Throws
ParseException when an error occurs during parsing

public abstract Date parse (String string, ParsePosition position)

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 Object parseObject (String string, ParsePosition position)

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.

Parameters
cal the Calendar

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.

Parameters
format the NumberFormat

public void setTimeZone (TimeZone timezone)

Sets the TimeZone of the Calendar used by this DateFormat.

Parameters
timezone the TimeZone