java.text

Class SimpleDateFormat

public class SimpleDateFormat extends DateFormat

SimpleDateFormat provides convenient methods for parsing and formatting dates using Gregorian calendars (see java.util.GregorianCalendar).
Constructor Summary
SimpleDateFormat()
Constructs a SimpleDateFormat using the default pattern for the default locale.
SimpleDateFormat(String pattern)
Creates a date formatter using the specified non-localized pattern, with the default DateFormatSymbols for the default locale.
SimpleDateFormat(String pattern, Locale locale)
Creates a date formatter using the specified non-localized pattern, with the default DateFormatSymbols for the given locale.
SimpleDateFormat(String pattern, DateFormatSymbols formatData)
Creates a date formatter using the specified non-localized pattern.
Method Summary
voidapplyLocalizedPattern(String pattern)
This method sets the formatting pattern that should be used by this object.
voidapplyPattern(String pattern)
This method sets the formatting pattern that should be used by this object.
Objectclone()
Returns a copy of this instance of SimpleDateFormat.
booleanequals(Object o)
This methods tests whether the specified object is equal to this object.
StringBufferformat(Date date, StringBuffer buffer, FieldPosition pos)
AttributedCharacterIteratorformatToCharacterIterator(Object date)
Dateget2DigitYearStart()
Returns the start of the century used for two digit years.
DateFormatSymbolsgetDateFormatSymbols()
This method returns a copy of the format symbol information used for parsing and formatting dates.
inthashCode()
This method returns a hash value for this object.
Dateparse(String dateStr, ParsePosition pos)
This method parses the specified string into a date.
voidset2DigitYearStart(Date date)
Sets the start of the century used for two digit years.
voidsetDateFormatSymbols(DateFormatSymbols formatData)
This method sets the format symbols information used for parsing and formatting dates.
StringtoLocalizedPattern()
This method returns a string with the formatting pattern being used by this object.
StringtoPattern()
This method returns a string with the formatting pattern being used by this object.
StringtoString()
Returns a string representation of this class.

Constructor Detail

SimpleDateFormat

public SimpleDateFormat()
Constructs a SimpleDateFormat using the default pattern for the default locale.

SimpleDateFormat

public SimpleDateFormat(String pattern)
Creates a date formatter using the specified non-localized pattern, with the default DateFormatSymbols for the default locale.

Parameters: pattern the pattern to use.

Throws: NullPointerException if the pattern is null. IllegalArgumentException if the pattern is invalid.

SimpleDateFormat

public SimpleDateFormat(String pattern, Locale locale)
Creates a date formatter using the specified non-localized pattern, with the default DateFormatSymbols for the given locale.

Parameters: pattern the non-localized pattern to use. locale the locale to use for the formatting symbols.

Throws: NullPointerException if the pattern is null. IllegalArgumentException if the pattern is invalid.

SimpleDateFormat

public SimpleDateFormat(String pattern, DateFormatSymbols formatData)
Creates a date formatter using the specified non-localized pattern. The specified DateFormatSymbols will be used when formatting.

Parameters: pattern the non-localized pattern to use. formatData the formatting symbols to use.

Throws: NullPointerException if the pattern or formatData is null. IllegalArgumentException if the pattern is invalid.

Method Detail

applyLocalizedPattern

public void applyLocalizedPattern(String pattern)
This method sets the formatting pattern that should be used by this object. This string is localized.

Parameters: pattern The new format pattern.

Throws: NullPointerException if the pattern is null. IllegalArgumentException if the pattern is invalid.

applyPattern

public void applyPattern(String pattern)
This method sets the formatting pattern that should be used by this object. This string is not localized.

Parameters: pattern The new format pattern.

Throws: NullPointerException if the pattern is null. IllegalArgumentException if the pattern is invalid.

clone

public Object clone()
Returns a copy of this instance of SimpleDateFormat. The copy contains clones of the formatting symbols and the 2-digit year century start date.

equals

public boolean equals(Object o)
This methods tests whether the specified object is equal to this object. This will be true if and only if the specified object:

Parameters: o The object to compare for equality against.

Returns: true if the specified object is equal to this object, false otherwise.

format

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

formatToCharacterIterator

public AttributedCharacterIterator formatToCharacterIterator(Object date)

get2DigitYearStart

public Date get2DigitYearStart()
Returns the start of the century used for two digit years.

Returns: A Date representing the start of the century for two digit years.

getDateFormatSymbols

public DateFormatSymbols getDateFormatSymbols()
This method returns a copy of the format symbol information used for parsing and formatting dates.

Returns: a copy of the date format symbols.

hashCode

public int hashCode()
This method returns a hash value for this object.

Returns: A hash value for this object.

parse

public Date parse(String dateStr, ParsePosition pos)
This method parses the specified string into a date.

Parameters: dateStr The date string to parse. pos The input and output parse position

Returns: The parsed date, or null if the string cannot be parsed.

set2DigitYearStart

public void set2DigitYearStart(Date date)
Sets the start of the century used for two digit years.

Parameters: date A Date representing the start of the century for two digit years.

setDateFormatSymbols

public void setDateFormatSymbols(DateFormatSymbols formatData)
This method sets the format symbols information used for parsing and formatting dates.

Parameters: formatData The date format symbols.

Throws: NullPointerException if formatData is null.

toLocalizedPattern

public String toLocalizedPattern()
This method returns a string with the formatting pattern being used by this object. This string is localized.

Returns: The format string.

toPattern

public String toPattern()
This method returns a string with the formatting pattern being used by this object. This string is unlocalized.

Returns: The format string.

toString

public String toString()
Returns a string representation of this class.

Returns: a string representation of the SimpleDateFormat instance.