Android
java.text
public class

java.text.SimpleDateFormat

java.lang.Object
java.text.Format Serializable Cloneable
java.text.DateFormat
java.text.SimpleDateFormat

SimpleDateFormat is used to format and parse Gregorian calendar dates and times based on a pattern of date and time fields. Each date and time field is specified in the pattern by a specific character. The characters used can be either localized or non-localized. For some fields, which have both numeric and text representations or abbreviated as well as full names, the number of grouped characters specifies how the field is formatted or parsed.

Summary

Constants inherited from class java.text.DateFormat
Fields inherited from class java.text.DateFormat

Public Constructors

            SimpleDateFormat()
Constructs a new SimpleDateFormat for formatting and parsing dates and times in the SHORT style for the default Locale.
            SimpleDateFormat(String pattern)
Constructs a new SimpleDateFormat using the specified non-localized pattern and the DateFormatSymbols and Calendar for the default Locale.
            SimpleDateFormat(String template, DateFormatSymbols value)
Constructs a new SimpleDateFormat using the specified non-localized pattern and DateFormatSymbols and the Calendar for the default Locale.
            SimpleDateFormat(String template, Locale locale)
Constructs a new SimpleDateFormat using the specified non-localized pattern and the DateFormatSymbols and Calendar for the specified Locale.

Public Methods

          void  applyLocalizedPattern(String template)
Changes the pattern of this SimpleDateFormat to the specified pattern which uses localized pattern characters.
          void  applyPattern(String template)
Changes the pattern of this SimpleDateFormat to the specified pattern which uses non-localized pattern characters.
          Object  clone()
Returns a new SimpleDateFormat with the same pattern and properties as this SimpleDateFormat.
          boolean  equals(Object object)
Compares the specified object to this SimpleDateFormat and answer if they are equal.
          StringBuffer  format(Date date, StringBuffer buffer, FieldPosition field)
Formats the specified Date into the specified StringBuffer using the pattern of this SimpleDateFormat.
          AttributedCharacterIterator  formatToCharacterIterator(Object object)
Formats the specified object using the rules of this SimpleDateFormat and returns an AttributedCharacterIterator with the formatted Date and attributes.
          Date  get2DigitYearStart()
Returns the Date which is the start of the one hundred year period for two digits year values.
          DateFormatSymbols  getDateFormatSymbols()
Returns the DateFormatSymbols used by this SimpleDateFormat.
          int  hashCode()
Returns an integer hash code for the receiver.
          Date  parse(String string, ParsePosition position)
Parse a Date from the specified String starting at the index specified by the ParsePosition.
          void  set2DigitYearStart(Date date)
Sets the Date which is the start of the one hundred year period for two digits year values.
          void  setDateFormatSymbols(DateFormatSymbols value)
Sets the DateFormatSymbols used by this SimpleDateFormat.
          String  toLocalizedPattern()
Returns the pattern of this SimpleDateFormat using localized pattern characters.
          String  toPattern()
Returns the pattern of this SimpleDateFormat using non-localized pattern characters.
Methods inherited from class java.text.DateFormat
Methods inherited from class java.text.Format
Methods inherited from class java.lang.Object

Details

Public Constructors

public SimpleDateFormat()

Constructs a new SimpleDateFormat for formatting and parsing dates and times in the SHORT style for the default Locale.

public SimpleDateFormat(String pattern)

Constructs a new SimpleDateFormat using the specified non-localized pattern and the DateFormatSymbols and Calendar for the default Locale.

Parameters

pattern the pattern

Throws

NullPointerException if a null value of pattern is supplied.
IllegalArgumentException if pattern is not considered to be useable by this formatter.

public SimpleDateFormat(String template, DateFormatSymbols value)

Constructs a new SimpleDateFormat using the specified non-localized pattern and DateFormatSymbols and the Calendar for the default Locale.

Parameters

template the pattern
value the DateFormatSymbols

Throws

NullPointerException if the pattern is null
IllegalArgumentException if the pattern is invalid

public SimpleDateFormat(String template, Locale locale)

Constructs a new SimpleDateFormat using the specified non-localized pattern and the DateFormatSymbols and Calendar for the specified Locale.

Parameters

template the pattern
locale the Locale

Throws

NullPointerException if the pattern is null
IllegalArgumentException if the pattern is invalid

Public Methods

public void applyLocalizedPattern(String template)

Changes the pattern of this SimpleDateFormat to the specified pattern which uses localized pattern characters.

Parameters

template the localized pattern

public void applyPattern(String template)

Changes the pattern of this SimpleDateFormat to the specified pattern which uses non-localized pattern characters.

Parameters

template the non-localized pattern

Throws

NullPointerException if the pattern is null
IllegalArgumentException if the pattern is invalid

public Object clone()

Returns a new SimpleDateFormat with the same pattern and properties as this SimpleDateFormat.

Returns

  • a shallow copy of this SimpleDateFormat

See Also

public boolean equals(Object object)

Compares the specified object to this SimpleDateFormat and answer if they are equal. The object must be an instance of SimpleDateFormat and have the same DateFormat properties, pattern, DateFormatSymbols, and creation year.

Parameters

object the object to compare with this object

Returns

  • true if the specified object is equal to this SimpleDateFormat, false otherwise

See Also

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

Formats the specified Date into the specified StringBuffer using the pattern of this SimpleDateFormat. 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

Throws

IllegalArgumentException when there are invalid characters in the pattern

public AttributedCharacterIterator formatToCharacterIterator(Object object)

Formats the specified object using the rules of this SimpleDateFormat and returns an AttributedCharacterIterator with the formatted Date and attributes.

Parameters

object the object to format

Returns

  • an AttributedCharacterIterator with the formatted date and attributes

Throws

NullPointerException when the object is null
IllegalArgumentException when the object cannot be formatted by this Format

public Date get2DigitYearStart()

Returns the Date which is the start of the one hundred year period for two digits year values.

Returns

  • a Date

public DateFormatSymbols getDateFormatSymbols()

Returns the DateFormatSymbols used by this SimpleDateFormat.

Returns

  • a DateFormatSymbols

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 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 according to the pattern of this SimpleDateFormat
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

Throws

IllegalArgumentException when there are invalid characters in the pattern

public void set2DigitYearStart(Date date)

Sets the Date which is the start of the one hundred year period for two digits year values.

Parameters

date the Date

public void setDateFormatSymbols(DateFormatSymbols value)

Sets the DateFormatSymbols used by this SimpleDateFormat.

Parameters

value the DateFormatSymbols

public String toLocalizedPattern()

Returns the pattern of this SimpleDateFormat using localized pattern characters.

Returns

  • the localized pattern

public String toPattern()

Returns the pattern of this SimpleDateFormat using non-localized pattern characters.

Returns

  • the non-localized pattern
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48