Package com.jidesoft.converter
Class DateConverter
- java.lang.Object
-
- com.jidesoft.converter.DateConverter
-
- All Implemented Interfaces:
ObjectConverter
- Direct Known Subclasses:
CalendarConverter
public class DateConverter extends java.lang.Object implements ObjectConverter
Converter which converts Date to String and converts it back.
-
-
Field Summary
Fields Modifier and Type Field Description static ConverterContextDATE_CONTEXTstatic ConverterContextDATETIME_CONTEXTstatic ConverterContextTIME_CONTEXT
-
Constructor Summary
Constructors Constructor Description DateConverter()Creates a DateConverter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectfromString(java.lang.String string, ConverterContext context)Converts from a String to a Date.java.text.DateFormatgetDefaultDatetimeFormat()Gets DefaultDatetimeFormat to format an calendar.java.text.DateFormatgetDefaultFormat()Gets DefaultFormat to format an calendar.java.text.DateFormatgetDefaultTimeFormat()Gets DefaultTimeFormat to format an calendar.voidsetDefaultDatetimeFormat(java.text.DateFormat defaultDatetimeFormat)Sets DefaultDatetimeFormat to format an calendar.voidsetDefaultFormat(java.text.DateFormat defaultFormat)Sets DefaultFormat to format an calendar.voidsetDefaultTimeFormat(java.text.DateFormat defaultTimeFormat)Sets DefaultTimeFormat to format an calendar.booleansupportFromString(java.lang.String string, ConverterContext context)If it supports fromString.booleansupportToString(java.lang.Object object, ConverterContext context)If it supports toString method.java.lang.StringtoString(java.lang.Object object, ConverterContext context)Converts the object to String.
-
-
-
Field Detail
-
DATETIME_CONTEXT
public static final ConverterContext DATETIME_CONTEXT
-
TIME_CONTEXT
public static final ConverterContext TIME_CONTEXT
-
DATE_CONTEXT
public static final ConverterContext DATE_CONTEXT
-
-
Method Detail
-
toString
public java.lang.String toString(java.lang.Object object, ConverterContext context)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:
toStringin interfaceObjectConverter- Parameters:
object- the object to be convertedcontext- the converter context.- Returns:
- the string
-
supportToString
public boolean supportToString(java.lang.Object object, ConverterContext context)Description copied from interface:ObjectConverterIf it supports toString method.- Specified by:
supportToStringin interfaceObjectConverter- Parameters:
object- object to be convertedcontext- converter context to be used- Returns:
- true if supports toString
-
fromString
public java.lang.Object fromString(java.lang.String string, ConverterContext context)Converts from a String to a Date.- Specified by:
fromStringin 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
public boolean supportFromString(java.lang.String string, ConverterContext context)Description copied from interface:ObjectConverterIf it supports fromString.- Specified by:
supportFromStringin interfaceObjectConverter- Parameters:
string- the stringcontext- context to be converted- Returns:
- true if it supports
-
getDefaultFormat
public java.text.DateFormat getDefaultFormat()
Gets DefaultFormat to format an calendar.- Returns:
- DefaultFormat
-
setDefaultFormat
public void setDefaultFormat(java.text.DateFormat defaultFormat)
Sets DefaultFormat to format an calendar.- Parameters:
defaultFormat- the new default date format
-
getDefaultTimeFormat
public java.text.DateFormat getDefaultTimeFormat()
Gets DefaultTimeFormat to format an calendar. This is used only when context isTIME_CONTEXT.- Returns:
- DefaultTimeFormat
-
setDefaultTimeFormat
public void setDefaultTimeFormat(java.text.DateFormat defaultTimeFormat)
Sets DefaultTimeFormat to format an calendar. This is used only when context isTIME_CONTEXT.- Parameters:
defaultTimeFormat- the new default time format
-
getDefaultDatetimeFormat
public java.text.DateFormat getDefaultDatetimeFormat()
Gets DefaultDatetimeFormat to format an calendar. This is used only when context isDATETIME_CONTEXT.- Returns:
- DefaultDatetimeFormat
-
setDefaultDatetimeFormat
public void setDefaultDatetimeFormat(java.text.DateFormat defaultDatetimeFormat)
Sets DefaultDatetimeFormat to format an calendar. This is used only when context isDATETIME_CONTEXT.- Parameters:
defaultDatetimeFormat- the new defaultdatetime format
-
-