public abstract class AbstractDateConverter<T> extends DefaultObjectConverter<T>
ObjectConverter implementation for <code>Date</code>, <code>Calendar</code>
or <code>Number</code>. All of aforementioned data types can be accepted by the toString method. For the fromString
method, it will only return <code>Date</code>. Its subclasses might return Calendar or Number.| Modifier and Type | Field and Description |
|---|---|
static ConverterContext |
CONTEXT_DATE
A converter context to tell the DateConverter using a DateFormat from SimpleDateFormat.getDateInstance to do the
conversion.
|
static ConverterContext |
CONTEXT_DATETIME
A converter context to tell the DateConverter using a DateFormat from SimpleDateFormat.getDateTimeInstance to do
the conversion.
|
static ConverterContext |
CONTEXT_TIME
A converter context to tell the DateConverter using a DateFormat from SimpleDateFormat.getTimeInstance to do the
conversion.
|
static java.lang.String |
PROPERTY_DATE_FORMAT
A property for the converter context.
|
| Constructor and Description |
|---|
AbstractDateConverter()
Creates a DateConverter.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
anyDateToString(java.lang.Object object,
ConverterContext context)
Converts the object to String.
|
java.lang.Object |
fromStringToDate(java.lang.String string,
ConverterContext context)
Converts from a String to a Date.
|
java.text.DateFormat |
getDefaultDateFormat()
Gets the default format for date.
|
java.text.DateFormat |
getDefaultDateTimeFormat()
Gets the default format for date/time.
|
java.text.DateFormat |
getDefaultTimeFormat()
Gets the default format for time.
|
void |
setDefaultDateFormat(java.text.DateFormat defaultDateFormat)
Sets the default format to format date.
|
void |
setDefaultDateTimeFormat(java.text.DateFormat defaultDateTimeFormat)
Sets the default format to format date/time.
|
void |
setDefaultTimeFormat(java.text.DateFormat defaultTimeFormat)
Sets the default format to format time.
|
fromString, fromString, getObjectConverterManager, toString, toString, toStringConverterpublic static final ConverterContext CONTEXT_DATETIME
public static final ConverterContext CONTEXT_TIME
public static final ConverterContext CONTEXT_DATE
public static final java.lang.String PROPERTY_DATE_FORMAT
public java.lang.String anyDateToString(java.lang.Object object,
ConverterContext context)
object - the object to be convertedcontext - the converter context.public java.lang.Object fromStringToDate(java.lang.String string,
ConverterContext context)
PROPERTY_DATE_FORMAT if any.
Otherwise it will try different default DateFormat according to the context (Date, Time or DateTime). At last it
will try the following commonly used format patterns in order of "M/d/yyyy", "MM/dd/yyyy", "yyyy-MM-dd",
"yy-MM-dd", "yyyyMMdd", "yyMMdd", "dd-MMM-yy", "dd-MMM-yyyy", until it finds a match. We do that so that users
could type in other date formats and still could be recognized.string - the string to be converted.context - the context.public java.text.DateFormat getDefaultDateFormat()
CONTEXT_DATE.public void setDefaultDateFormat(java.text.DateFormat defaultDateFormat)
CONTEXT_DATE.defaultDateFormat - the new default format for date.public java.text.DateFormat getDefaultTimeFormat()
CONTEXT_TIME.public void setDefaultTimeFormat(java.text.DateFormat defaultTimeFormat)
CONTEXT_TIME.defaultTimeFormat - the new default format for time.public java.text.DateFormat getDefaultDateTimeFormat()
CONTEXT_DATETIME.public void setDefaultDateTimeFormat(java.text.DateFormat defaultDateTimeFormat)
CONTEXT_DATETIME.defaultDateTimeFormat - the new default format for date/time.