Package joptsimple.util
Class DateConverter
- java.lang.Object
-
- joptsimple.util.DateConverter
-
- All Implemented Interfaces:
ValueConverter<Date>
public class DateConverter extends Object implements ValueConverter<Date>
Converts values toDates using aDateFormatobject.- Author:
- Paul Holser
-
-
Constructor Summary
Constructors Constructor Description DateConverter(DateFormat formatter)Creates a converter that uses the given date formatter/parser.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Dateconvert(String value)Converts the given string value into a Java type.static DateConverterdatePattern(String pattern)Creates a converter that uses aSimpleDateFormatwith the given date/time pattern.StringvaluePattern()Gives a string that describes the pattern of the values this converter expects, if any.Class<Date>valueType()Gives the class of the type of values this converter converts to.
-
-
-
Constructor Detail
-
DateConverter
public DateConverter(DateFormat formatter)
Creates a converter that uses the given date formatter/parser.- Parameters:
formatter- the formatter/parser to use- Throws:
NullPointerException- ifformatterisnull
-
-
Method Detail
-
datePattern
public static DateConverter datePattern(String pattern)
Creates a converter that uses aSimpleDateFormatwith the given date/time pattern. The date formatter created is notlenient.- Parameters:
pattern- expected date/time pattern- Returns:
- the new converter
- Throws:
NullPointerException- ifpatternisnullIllegalArgumentException- ifpatternis invalid
-
convert
public Date convert(String value)
Description copied from interface:ValueConverterConverts the given string value into a Java type.- Specified by:
convertin interfaceValueConverter<Date>- Parameters:
value- the string to convert- Returns:
- the converted value
-
valueType
public Class<Date> valueType()
Description copied from interface:ValueConverterGives the class of the type of values this converter converts to.- Specified by:
valueTypein interfaceValueConverter<Date>- Returns:
- the target class for conversion
-
valuePattern
public String valuePattern()
Description copied from interface:ValueConverterGives a string that describes the pattern of the values this converter expects, if any. For example, a date converter can respond with adate format string.- Specified by:
valuePatternin interfaceValueConverter<Date>- Returns:
- a value pattern, or
nullif there's nothing interesting here
-
-