Package com.jidesoft.converter
Class DateConverter
java.lang.Object
com.jidesoft.converter.DateConverter
- All Implemented Interfaces:
ObjectConverter
- Direct Known Subclasses:
CalendarConverter
Converter which converts Date to String and converts it back.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConverterContext
static final ConverterContext
static final ConverterContext
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfromString
(String string, ConverterContext context) Converts from a String to a Date.Gets DefaultDatetimeFormat to format an calendar.Gets DefaultFormat to format an calendar.Gets DefaultTimeFormat to format an calendar.void
setDefaultDatetimeFormat
(DateFormat defaultDatetimeFormat) Sets DefaultDatetimeFormat to format an calendar.void
setDefaultFormat
(DateFormat defaultFormat) Sets DefaultFormat to format an calendar.void
setDefaultTimeFormat
(DateFormat defaultTimeFormat) Sets DefaultTimeFormat to format an calendar.boolean
supportFromString
(String string, ConverterContext context) If it supports fromString.boolean
supportToString
(Object object, ConverterContext context) If it supports toString method.toString
(Object object, ConverterContext context) Converts the object to String.
-
Field Details
-
DATETIME_CONTEXT
-
TIME_CONTEXT
-
DATE_CONTEXT
-
-
Constructor Details
-
DateConverter
public DateConverter()Creates a DateConverter.
-
-
Method Details
-
toString
Converts the object to String. The object can be a Calendar, a Date or a Number. As long as the DateFormat can format it correctly, it will be converted to a String. If the object is already a String, we will return it directly as it is.- Specified by:
toString
in interfaceObjectConverter
- Parameters:
object
- the object to be convertedcontext
- the converter context.- Returns:
- the string
-
supportToString
Description copied from interface:ObjectConverter
If it supports toString method.- Specified by:
supportToString
in interfaceObjectConverter
- Parameters:
object
- object to be convertedcontext
- converter context to be used- Returns:
- true if supports toString
-
fromString
Converts from a String to a Date.- Specified by:
fromString
in interfaceObjectConverter
- Parameters:
string
- the string to be converted.context
- the context. It could be DATETIME_CONTEXT, DATE_CONTEXT or TIME_CONTEXT.- Returns:
- the Date. If the string is null or empty, null will be returned. If the string cannot be parsed as a date, the string itself will be returned.
-
supportFromString
Description copied from interface:ObjectConverter
If it supports fromString.- Specified by:
supportFromString
in interfaceObjectConverter
- Parameters:
string
- the stringcontext
- context to be converted- Returns:
- true if it supports
-
getDefaultFormat
Gets DefaultFormat to format an calendar.- Returns:
- DefaultFormat
-
setDefaultFormat
Sets DefaultFormat to format an calendar.- Parameters:
defaultFormat
- the new default date format
-
getDefaultTimeFormat
Gets DefaultTimeFormat to format an calendar. This is used only when context isTIME_CONTEXT
.- Returns:
- DefaultTimeFormat
-
setDefaultTimeFormat
Sets DefaultTimeFormat to format an calendar. This is used only when context isTIME_CONTEXT
.- Parameters:
defaultTimeFormat
- the new default time format
-
getDefaultDatetimeFormat
Gets DefaultDatetimeFormat to format an calendar. This is used only when context isDATETIME_CONTEXT
.- Returns:
- DefaultDatetimeFormat
-
setDefaultDatetimeFormat
Sets DefaultDatetimeFormat to format an calendar. This is used only when context isDATETIME_CONTEXT
.- Parameters:
defaultDatetimeFormat
- the new defaultdatetime format
-