java.text
Class SimpleDateFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
          extended by java.text.SimpleDateFormat
All Implemented Interfaces:
Serializable, Cloneable

public class SimpleDateFormat
extends DateFormat

SimpleDateFormat provides convenient methods for parsing and formatting dates using Gregorian calendars (see java.util.GregorianCalendar).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field
 
Field Summary
 
Fields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, EXTENDED_YEAR_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, ISO_YEAR_FIELD, LOCALIZED_DAY_OF_WEEK_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MILLISECOND_IN_DAY_FIELD, MINUTE_FIELD, MODIFIED_JULIAN_DAY_FIELD, MONTH_FIELD, numberFormat, RFC822_TIMEZONE_FIELD, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
 
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, DateFormatSymbols formatData)
          Creates a date formatter using the specified non-localized pattern.
SimpleDateFormat(String pattern, Locale locale)
          Creates a date formatter using the specified non-localized pattern, with the default DateFormatSymbols for the given locale.
 
Method Summary
 void applyLocalizedPattern(String pattern)
          This method sets the formatting pattern that should be used by this object.
 void applyPattern(String pattern)
          This method sets the formatting pattern that should be used by this object.
 Object clone()
          Returns a copy of this instance of SimpleDateFormat.
 boolean equals(Object o)
          This methods tests whether the specified object is equal to this object.
 StringBuffer format(Date date, StringBuffer buffer, FieldPosition pos)
          This method formats a Date into a string and appends it to the specified StringBuffer.
 AttributedCharacterIterator formatToCharacterIterator(Object date)
           
 Date get2DigitYearStart()
          Returns the start of the century used for two digit years.
 DateFormatSymbols getDateFormatSymbols()
          This method returns a copy of the format symbol information used for parsing and formatting dates.
 int hashCode()
          This method returns a hash value for this object.
 Date parse(String dateStr, ParsePosition pos)
          This method parses the specified string into a date.
 void set2DigitYearStart(Date date)
          Sets the start of the century used for two digit years.
 void setDateFormatSymbols(DateFormatSymbols formatData)
          This method sets the format symbols information used for parsing and formatting dates.
 String toLocalizedPattern()
          This method returns a string with the formatting pattern being used by this object.
 String toPattern()
          This method returns a string with the formatting pattern being used by this object.
 String toString()
          Returns a string representation of this class.
 
Methods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
 
Methods inherited from class java.text.Format
format, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

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

toString

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

Overrides:
toString in class Object
Returns:
a string representation of the SimpleDateFormat instance.
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)

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.

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.

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.

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.

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.

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.

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.

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.

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:

Overrides:
equals in class DateFormat
Parameters:
o - The object to compare for equality against.
Returns:
true if the specified object is equal to this object, false otherwise.
See Also:
Object.hashCode()

hashCode

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

Overrides:
hashCode in class DateFormat
Returns:
A hash value for this object.
See Also:
Object.equals(Object), System.identityHashCode(Object)

format

public StringBuffer format(Date date,
                           StringBuffer buffer,
                           FieldPosition pos)
Description copied from class: DateFormat
This method formats a Date into a string and appends it to the specified StringBuffer.

Specified by:
format in class DateFormat
Parameters:
date - The Date value to format.
buffer - The StringBuffer to append the resultant String to.
pos - Is updated to the start and end index of the specified field.
Returns:
The StringBuffer supplied on input, with the formatted date/time appended.

formatToCharacterIterator

public AttributedCharacterIterator formatToCharacterIterator(Object date)
                                                      throws IllegalArgumentException
Overrides:
formatToCharacterIterator in class Format
Throws:
IllegalArgumentException

parse

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

Specified by:
parse in class DateFormat
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.

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.

Overrides:
clone in class DateFormat
Returns:
A copy of this object.
See Also:
Cloneable