public class DateParser extends java.lang.Object implements ValueParser<java.util.Date>
Date. There are many formats of a date
can be represented in. As a result, this parser must be given an appropriate
date DateFormat object to know how to parse a string into a
date. In particular situations where the same format is being used for a
larger more complicated parser, it may be more appropriate to subclass this
object and hard code the format into the class.| Modifier and Type | Field and Description |
|---|---|
static DateParser |
PARSER
Simple date format that accepts dates in the default ISO 8601 format yyyy-MM-dd
|
| Constructor and Description |
|---|
DateParser() |
DateParser(java.text.DateFormat format) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
format(java.util.Date date)
Takes a date and returns a string representation of it using the format
this parser uses to convert strings into dates.
|
java.lang.Class<java.util.Date> |
getType()
Returns the
Class of object this ValueParser can handle. |
java.util.Date |
parse(java.lang.String valueString)
Parses the specified string and constructs the appropriate object out of
it.
|
public static final DateParser PARSER
public DateParser(java.text.DateFormat format)
public DateParser()
public java.lang.Class<java.util.Date> getType()
ValueParserClass of object this ValueParser can handle.
The ValueParser.parse(String) method must return objects that are assignable to this type.
The #format(T) method can format any object assignable to this type.
The returned class will be the
exact Class (i.e. not a subclass) of this
ValueParser's typegetType in interface ValueFormatter<java.util.Date>getType in interface ValueParser<java.util.Date>ValueParserpublic java.util.Date parse(java.lang.String valueString)
throws ValueParseException
ValueParserparse in interface ValueParser<java.util.Date>ValueParseException - If valueString is not of a format that allows this
parser to convert it into an object of type TvalueString - The string to parsevalueStringpublic java.lang.String format(java.util.Date date)
format in interface ValueFormatter<java.util.Date>format in interface ValueParser<java.util.Date>date - The date to be converted into a stringdate in string format