Top Description Methods
org.apache.commons.lang3.time

public Interface DateParser

Known Direct Implementers
org.apache.commons.lang3.time.FastDateFormat, org.apache.commons.lang3.time.FastDateParser
Imports
java.text.ParseException, .ParsePosition, java.util.Calendar, .Date, .Locale, .TimeZone

DateParser is the "missing" interface for the parsing methods of java.text.DateFormat. You can obtain an object implementing this interface by using one of the FastDateFormat factory methods.

Warning

Since binary compatible methods may be added to this interface in any release, developers are not expected to implement this interface.

Since
3.2

Method Summary

Modifier and TypeMethod and Description
public Locale

Returns:

the locale
getLocale
()

Gets the locale used by this parser.

public String

Returns:

the pattern, java.text.SimpleDateFormat compatible.
getPattern
()

Gets the pattern used by this parser.

public TimeZone

Returns:

the time zone
getTimeZone
()

Gets the time zone used by this parser.

public Date

Returns:

A Date parsed from the string.
parse
(String
A String whose beginning should be parsed.
source
)

Equivalent to DateFormat.parse(String).

public Date

Returns:

A Date parsed from the string. In case of error, returns null.
parse
(String
A String, part of which should be parsed.
source
,
ParsePosition
A ParsePosition object with index and error index information as described above.
pos
)

Equivalent to DateFormat.parse(String, ParsePosition).

public boolean

Returns:

true, if source has been parsed (pos parsePosition is updated); otherwise false (and pos errorIndex is updated)
parse
(String
The text to parse.
source
,
ParsePosition
On input, the position in the source to start parsing, on output, updated position.
pos
,
Calendar
The calendar into which to set parsed fields.
calendar
)

Parses a formatted date string according to the format.

public Object

Returns:

a java.util.Date object.
parseObject
(String
A String whose beginning should be parsed.
source
)

Parses text from a string to produce a Date.

public Object

Returns:

a java.util.Date object.
parseObject
(String
A String whose beginning should be parsed.
source
,
ParsePosition
the parse position.
pos
)

Parses a date/time string according to the given parse position.

Method Detail

getLocaleback to summary
public Locale getLocale()

Gets the locale used by this parser.

Returns:Locale

the locale

getPatternback to summary
public String getPattern()

Gets the pattern used by this parser.

Returns:String

the pattern, java.text.SimpleDateFormat compatible.

getTimeZoneback to summary
public TimeZone getTimeZone()

Gets the time zone used by this parser.

The default TimeZone used to create a Date when the TimeZone is not specified by the format pattern.

Returns:TimeZone

the time zone

parseback to summary
public Date parse(String source) throws ParseException

Equivalent to DateFormat.parse(String). See java.text.DateFormat#parse(String) for more information.

Parameters
source:String

A String whose beginning should be parsed.

Returns:Date

A Date parsed from the string.

Exceptions
ParseException:
if the beginning of the specified string cannot be parsed.
parseback to summary
public Date parse(String source, ParsePosition pos)

Equivalent to DateFormat.parse(String, ParsePosition). See java.text.DateFormat#parse(String, ParsePosition) for more information.

Parameters
source:String

A String, part of which should be parsed.

pos:ParsePosition

A ParsePosition object with index and error index information as described above.

Returns:Date

A Date parsed from the string. In case of error, returns null.

Exceptions
NullPointerException:
if text or pos is null.
parseback to summary
public boolean parse(String source, ParsePosition pos, Calendar calendar)

Parses a formatted date string according to the format. Updates the Calendar with parsed fields. Upon success, the ParsePosition index is updated to indicate how much of the source text was consumed. Not all source text needs to be consumed. Upon parse failure, ParsePosition error index is updated to the offset of the source text which does not match the supplied format.

Parameters
source:String

The text to parse.

pos:ParsePosition

On input, the position in the source to start parsing, on output, updated position.

calendar:Calendar

The calendar into which to set parsed fields.

Returns:boolean

true, if source has been parsed (pos parsePosition is updated); otherwise false (and pos errorIndex is updated)

Exceptions
IllegalArgumentException:
when Calendar has been set to be not lenient, and a parsed field is out of range.
Since
3.5
parseObjectback to summary
public Object parseObject(String source) throws ParseException

Parses text from a string to produce a Date.

Parameters
source:String

A String whose beginning should be parsed.

Returns:Object

a java.util.Date object.

Exceptions
ParseException:
if the beginning of the specified string cannot be parsed.
See Also
java.text.DateFormat#parseObject(String)
parseObjectback to summary
public Object parseObject(String source, ParsePosition pos)

Parses a date/time string according to the given parse position.

Parameters
source:String

A String whose beginning should be parsed.

pos:ParsePosition

the parse position.

Returns:Object

a java.util.Date object.

See Also
java.text.DateFormat#parseObject(String, ParsePosition)