Package org.apache.commons.lang3.time
Interface DateParser
-
- All Known Implementing Classes:
FastDateFormat,FastDateParser
public interface DateParserDateParser is the "missing" interface for the parsing methods ofDateFormat. 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.LocalegetLocale()Gets the locale used by this parser.java.lang.StringgetPattern()Gets the pattern used by this parser.java.util.TimeZonegetTimeZone()Gets the time zone used by this parser.java.util.Dateparse(java.lang.String source)Equivalent to DateFormat.parse(String).java.util.Dateparse(java.lang.String source, java.text.ParsePosition pos)Equivalent to DateFormat.parse(String, ParsePosition).booleanparse(java.lang.String source, java.text.ParsePosition pos, java.util.Calendar calendar)Parses a formatted date string according to the format.java.lang.ObjectparseObject(java.lang.String source)Parses text from a string to produce a Date.java.lang.ObjectparseObject(java.lang.String source, java.text.ParsePosition pos)Parses a date/time string according to the given parse position.
-
-
-
Method Detail
-
parse
java.util.Date parse(java.lang.String source) throws java.text.ParseExceptionEquivalent to DateFormat.parse(String). SeeDateFormat.parse(String)for more information.- Parameters:
source- AStringwhose beginning should be parsed.- Returns:
- A
Dateparsed from the string - Throws:
java.text.ParseException- if the beginning of the specified string cannot be parsed.
-
parse
java.util.Date parse(java.lang.String source, java.text.ParsePosition pos)Equivalent to DateFormat.parse(String, ParsePosition). SeeDateFormat.parse(String, ParsePosition)for more information.- Parameters:
source- AString, part of which should be parsed.pos- AParsePositionobject 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- if text or pos is null.
-
parse
boolean parse(java.lang.String source, java.text.ParsePosition pos, java.util.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- 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- when Calendar has been set to be not lenient, and a parsed field is out of range.- Since:
- 3.5
-
getPattern
java.lang.String getPattern()
Gets the pattern used by this parser.
- Returns:
- the pattern,
SimpleDateFormatcompatible
-
getTimeZone
java.util.TimeZone getTimeZone()
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
-
getLocale
java.util.Locale getLocale()
Gets the locale used by this parser.
- Returns:
- the locale
-
parseObject
java.lang.Object parseObject(java.lang.String source) throws java.text.ParseExceptionParses text from a string to produce a Date.- Parameters:
source- AStringwhose beginning should be parsed.- Returns:
- a
java.util.Dateobject - Throws:
java.text.ParseException- if the beginning of the specified string cannot be parsed.- See Also:
Format.parseObject(String)
-
parseObject
java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)Parses a date/time string according to the given parse position.- Parameters:
source- AStringwhose beginning should be parsed.pos- the parse position- Returns:
- a
java.util.Dateobject - See Also:
DateFormat.parseObject(String, ParsePosition)
-
-