Class DateConverter

java.lang.Object
com.jidesoft.converter.DateConverter
All Implemented Interfaces:
ObjectConverter
Direct Known Subclasses:
CalendarConverter

public class DateConverter extends Object implements ObjectConverter
Converter which converts Date to String and converts it back.
  • Field Details

  • Constructor Details

    • DateConverter

      public DateConverter()
      Creates a DateConverter.
  • Method Details

    • toString

      public String toString(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:
      toString in interface ObjectConverter
      Parameters:
      object - the object to be converted
      context - the converter context.
      Returns:
      the string
    • supportToString

      public boolean supportToString(Object object, ConverterContext context)
      Description copied from interface: ObjectConverter
      If it supports toString method.
      Specified by:
      supportToString in interface ObjectConverter
      Parameters:
      object - object to be converted
      context - converter context to be used
      Returns:
      true if supports toString
    • fromString

      public Object fromString(String string, ConverterContext context)
      Converts from a String to a Date.
      Specified by:
      fromString in interface ObjectConverter
      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(String string, ConverterContext context)
      Description copied from interface: ObjectConverter
      If it supports fromString.
      Specified by:
      supportFromString in interface ObjectConverter
      Parameters:
      string - the string
      context - context to be converted
      Returns:
      true if it supports
    • getDefaultFormat

      public DateFormat getDefaultFormat()
      Gets DefaultFormat to format an calendar.
      Returns:
      DefaultFormat
    • setDefaultFormat

      public void setDefaultFormat(DateFormat defaultFormat)
      Sets DefaultFormat to format an calendar.
      Parameters:
      defaultFormat - the new default date format
    • getDefaultTimeFormat

      public DateFormat getDefaultTimeFormat()
      Gets DefaultTimeFormat to format an calendar. This is used only when context is TIME_CONTEXT.
      Returns:
      DefaultTimeFormat
    • setDefaultTimeFormat

      public void setDefaultTimeFormat(DateFormat defaultTimeFormat)
      Sets DefaultTimeFormat to format an calendar. This is used only when context is TIME_CONTEXT.
      Parameters:
      defaultTimeFormat - the new default time format
    • getDefaultDatetimeFormat

      public DateFormat getDefaultDatetimeFormat()
      Gets DefaultDatetimeFormat to format an calendar. This is used only when context is DATETIME_CONTEXT.
      Returns:
      DefaultDatetimeFormat
    • setDefaultDatetimeFormat

      public void setDefaultDatetimeFormat(DateFormat defaultDatetimeFormat)
      Sets DefaultDatetimeFormat to format an calendar. This is used only when context is DATETIME_CONTEXT.
      Parameters:
      defaultDatetimeFormat - the new defaultdatetime format