DateParser
- public abstract interface org.apache.commons.lang3.time.DateParser[source]
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
Methods
Gets the locale used by this parser. |
|
Gets the pattern used by this parser. |
|
Gets the time zone used by this parser. |
|
Equivalent to DateFormat.parse(String). |
|
Equivalent to DateFormat.parse(String, ParsePosition). |
|
Parses a formatted date string according to the format. |
|
Parses text from a string to produce a Date. |
|
Parses a date/time string according to the given parse position. |
- public abstract Locale getLocale()[source]
Gets the locale used by this parser.
- Returns:
The locale
- public abstract String getPattern()[source]
Gets the pattern used by this parser.
- Returns:
The pattern,
java.text.SimpleDateFormatcompatible.
- public abstract TimeZone getTimeZone()[source]
Gets the time zone used by this parser.
The default
TimeZoneused to create aDatewhen theTimeZoneis not specified by the format pattern.- Returns:
The time zone
- public abstract Date parse(String source) throws ParseException[source]
Equivalent to DateFormat.parse(String). See
java.text.DateFormat#parse(String)for more information.
- public abstract Date parse(String source, ParsePosition pos)[source]
Equivalent to DateFormat.parse(String, ParsePosition). See
java.text.DateFormat#parse(String, ParsePosition)for more information.- Parameters:
source – A
String, part of which should be parsed.pos – A
ParsePositionobject with index and error index information as described above.
- Returns:
A
Dateparsed from the string. In case of error, returns null.- Throws:
java.lang.NullPointerException – Thrown if text or pos is null.
- public abstract boolean parse(String source, ParsePosition pos, Calendar calendar)[source]
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 – The text to parse.
pos – On input, the position in the source to start parsing, on output, updated position.
calendar – The calendar into which to set parsed fields.
- Returns:
true, if source has been parsed (pos parsePosition is updated); otherwise false (and pos errorIndex is updated)
- Throws:
java.lang.IllegalArgumentException – Thrown when Calendar has been set to be not lenient, and a parsed field is out of range.
- Since:
3.5
- public abstract Object parseObject(String source) throws ParseException[source]
Parses text from a string to produce a Date.
- Parameters:
source – A
Stringwhose beginning should be parsed.- Returns:
A
java.util.Dateobject.- Throws:
java.text.ParseException – Thrown if the beginning of the specified string cannot be parsed.
- See also:
- public abstract Object parseObject(String source, ParsePosition pos)[source]
Parses a date/time string according to the given parse position.
- Parameters:
source – A
Stringwhose beginning should be parsed.pos – The parse position.
- Returns:
A
java.util.Dateobject.- See also: