Class DateConverter

  • All Implemented Interfaces:
    PropertyConverter

    public class DateConverter
    extends NumberConverter
    Converts strings to dates and back.

    This class has a static cache of DateFormats, to avoid creation and parsing of date formats every time one is used.

    Version:
    $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/convert/DateConverter.java#2 $
    • Constructor Summary

      Constructors 
      Constructor Description
      DateConverter()
      Creates a DateConverter
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.text.DateFormat getDateFormat​(java.lang.String pFormat)  
      java.lang.Object toObject​(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat)
      Converts the string to a date, using the given format for parsing.
      java.lang.String toString​(java.lang.Object pObject, java.lang.String pFormat)
      Converts the object to a string, using the given format
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DateConverter

        public DateConverter()
        Creates a DateConverter
    • Method Detail

      • toObject

        public java.lang.Object toObject​(java.lang.String pString,
                                         java.lang.Class pType,
                                         java.lang.String pFormat)
                                  throws ConversionException
        Converts the string to a date, using the given format for parsing.
        Specified by:
        toObject in interface PropertyConverter
        Overrides:
        toObject in class NumberConverter
        Parameters:
        pString - the string to convert.
        pType - the type to convert to. java.util.Date and subclasses allowed.
        pFormat - the format used for parsing. Must be a legal SimpleDateFormat format, or null which will use the default format.
        Returns:
        the object created from the given string. May safely be typecast to java.util.Date
        Throws:
        ConversionException
        See Also:
        Date, DateFormat
      • toString

        public java.lang.String toString​(java.lang.Object pObject,
                                         java.lang.String pFormat)
                                  throws ConversionException
        Converts the object to a string, using the given format
        Specified by:
        toString in interface PropertyConverter
        Overrides:
        toString in class NumberConverter
        Parameters:
        pObject - the object to convert.
        pFormat - the format used for conversion. Must be a legal SimpleDateFormat format, or null which will use the default format.
        Returns:
        the string representation of the object, on the correct format.
        Throws:
        ConversionException - if the object is not a subclass of java.util.Date
        See Also:
        Date, DateFormat
      • getDateFormat

        private java.text.DateFormat getDateFormat​(java.lang.String pFormat)