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
AM_PM_FIELD,
DATE_FIELD,
DAY_OF_WEEK_FIELD,
DAY_OF_WEEK_IN_MONTH_FIELD,
DAY_OF_YEAR_FIELD,
DEFAULT,
ERA_FIELD,
FULL,
HOUR0_FIELD,
HOUR1_FIELD,
HOUR_OF_DAY0_FIELD,
HOUR_OF_DAY1_FIELD,
LONG,
MEDIUM,
MILLISECOND_FIELD,
MINUTE_FIELD,
MONTH_FIELD,
SECOND_FIELD,
SHORT,
TIMEZONE_FIELD,
WEEK_OF_MONTH_FIELD,
WEEK_OF_YEAR_FIELD,
YEAR_FIELD
Public Constructors
Public Methods
clone,
equals,
format,
format,
format,
getAvailableLocales,
getCalendar,
getDateInstance,
getDateInstance,
getDateInstance,
getDateTimeInstance,
getDateTimeInstance,
getDateTimeInstance,
getInstance,
getNumberFormat,
getTimeInstance,
getTimeInstance,
getTimeInstance,
getTimeZone,
hashCode,
isLenient,
parse,
parse,
parseObject,
setCalendar,
setLenient,
setNumberFormat,
setTimeZone
|
|
|
|
|
Object |
clone() |
|
|
|
|
|
boolean |
equals(Object object) |
|
|
final |
|
|
StringBuffer |
format(Object object, StringBuffer buffer, FieldPosition field) |
|
|
final |
|
|
String |
format(Date date) |
abstract |
|
|
|
|
StringBuffer |
format(Date date, StringBuffer buffer, FieldPosition field) |
|
|
|
static |
|
Locale[] |
getAvailableLocales() |
|
|
|
|
|
Calendar |
getCalendar() |
|
|
final |
static |
|
DateFormat |
getDateInstance(int style, Locale locale) |
|
|
final |
static |
|
DateFormat |
getDateInstance() |
|
|
final |
static |
|
DateFormat |
getDateInstance(int style) |
|
|
final |
static |
|
DateFormat |
getDateTimeInstance(int dateStyle, int timeStyle) |
|
|
final |
static |
|
DateFormat |
getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) |
|
|
final |
static |
|
DateFormat |
getDateTimeInstance() |
|
|
final |
static |
|
DateFormat |
getInstance() |
|
|
|
|
|
NumberFormat |
getNumberFormat() |
|
|
final |
static |
|
DateFormat |
getTimeInstance(int style) |
|
|
final |
static |
|
DateFormat |
getTimeInstance() |
|
|
final |
static |
|
DateFormat |
getTimeInstance(int style, Locale locale) |
|
|
|
|
|
TimeZone |
getTimeZone() |
|
|
|
|
|
int |
hashCode() |
|
|
|
|
|
boolean |
isLenient() |
|
|
|
|
|
Date |
parse(String string) |
abstract |
|
|
|
|
Date |
parse(String string, ParsePosition position) |
|
|
|
|
|
Object |
parseObject(String string, ParsePosition position) |
|
|
|
|
|
void |
setCalendar(Calendar cal) |
|
|
|
|
|
void |
setLenient(boolean value) |
|
|
|
|
|
void |
setNumberFormat(NumberFormat format) |
|
|
|
|
|
void |
setTimeZone(TimeZone timezone) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
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.
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 |
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 |
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 |
public
Object
clone()
Returns a new SimpleDateFormat with the same pattern and properties as
this SimpleDateFormat.
Returns
- a shallow copy of this SimpleDateFormat
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
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
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
public
Date
get2DigitYearStart()
Returns the Date which is the start of the one hundred year period for
two digits year values.
Returns the DateFormatSymbols used by this SimpleDateFormat.
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
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
public
void
set2DigitYearStart(Date date)
Sets the Date which is the start of the one hundred year period for two
digits year values.
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.
public
String
toPattern()
Returns the pattern of this SimpleDateFormat using non-localized pattern
characters.
Returns
- the non-localized pattern