|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.text.Format
java.text.DateFormat
java.text.SimpleDateFormat
public class SimpleDateFormat
SimpleDateFormat provides convenient methods for parsing and formatting dates using Gregorian calendars (see java.util.GregorianCalendar). This class is not thread-safe; external synchronisation should be applied if an instance is to be accessed from multiple threads.
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, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, 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 |
---|
public SimpleDateFormat()
public SimpleDateFormat(String pattern)
pattern
- the pattern to use.
NullPointerException
- if the pattern is null.
IllegalArgumentException
- if the pattern is invalid.public SimpleDateFormat(String pattern, Locale locale)
pattern
- the non-localized pattern to use.locale
- the locale to use for the formatting symbols.
NullPointerException
- if the pattern is null.
IllegalArgumentException
- if the pattern is invalid.public SimpleDateFormat(String pattern, DateFormatSymbols formatData)
pattern
- the non-localized pattern to use.formatData
- the formatting symbols to use.
NullPointerException
- if the pattern or formatData is null.
IllegalArgumentException
- if the pattern is invalid.Method Detail |
---|
public String toString()
toString
in class Object
SimpleDateFormat
instance.Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public String toPattern()
public String toLocalizedPattern()
public void applyPattern(String pattern)
pattern
- The new format pattern.
NullPointerException
- if the pattern is null.
IllegalArgumentException
- if the pattern is invalid.public void applyLocalizedPattern(String pattern)
pattern
- The new format pattern.
NullPointerException
- if the pattern is null.
IllegalArgumentException
- if the pattern is invalid.public Date get2DigitYearStart()
Date
representing the start of the century
for two digit years.public void set2DigitYearStart(Date date)
date
- A Date
representing the start of the century for
two digit years.public DateFormatSymbols getDateFormatSymbols()
public void setDateFormatSymbols(DateFormatSymbols formatData)
formatData
- The date format symbols.
NullPointerException
- if formatData
is null.public boolean equals(Object o)
null
.SimpleDateFormat
.DateFormat
)
level.
equals
in class DateFormat
o
- The object to compare for equality against.
true
if the specified object is equal to this object,
false
otherwise.Object.hashCode()
public int hashCode()
hashCode
in class DateFormat
Object.equals(Object)
,
System.identityHashCode(Object)
public StringBuffer format(Date date, StringBuffer buffer, FieldPosition pos)
DateFormat
Date
into a string and appends it
to the specified StringBuffer
.
format
in class DateFormat
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.
StringBuffer
supplied on input, with the
formatted date/time appended.public AttributedCharacterIterator formatToCharacterIterator(Object date) throws IllegalArgumentException
formatToCharacterIterator
in class Format
IllegalArgumentException
public Date parse(String dateStr, ParsePosition pos)
parse
in class DateFormat
dateStr
- The date string to parse.pos
- The input and output parse position
null
if the string cannot be
parsed.public Object clone()
SimpleDateFormat
. The copy contains
clones of the formatting symbols and the 2-digit
year century start date.
clone
in class DateFormat
Cloneable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |