DateParser (Apache Commons Lang 3.20.0 API)
Description: declaration: package: org.apache.commons.lang3.time, interface: DateParser

# Interface DateParser

All Known Implementing Classes:
  `FastDateFormat, FastDateParser`

public interface DateParser
DateParser is the "missing" interface for the parsing methods of `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 Type
  Method
  Description
  `Locale`
  `getLocale()`
  Gets the locale used by this parser.
  `String`
  `getPattern()`
  Gets the pattern used by this parser.
  `TimeZone`
  `getTimeZone()`
  Gets the time zone used by this parser.
  `Date`
  `parse(String source)`
  Equivalent to DateFormat.parse(String).
  `Date`
  `parse(String source, ParsePosition pos)`
  Equivalent to DateFormat.parse(String, ParsePosition).
  `boolean`
  `parse(String source, ParsePosition pos, Calendar calendar)`
  Parses a formatted date string according to the format.
  `Object`
  `parseObject(String source)`
  Parses text from a string to produce a Date.
  `Object`
  `parseObject(String source, ParsePosition pos)`
  Parses a date/time string according to the given parse position.

- ## Method Details

  - ### getLocale

    Locale getLocale()
    Gets the locale used by this parser.
    Returns:
      the locale

  - ### getPattern

    String getPattern()
    Gets the pattern used by this parser.
    Returns:
      the pattern, `SimpleDateFormat` compatible.

  - ### getTimeZone

    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:
      the time zone

  - ### parse

    Date parse(String source) throws ParseException
    Equivalent to DateFormat.parse(String). See `DateFormat.parse(String)` for more information.
    Parameters:
      `source` - A `String` whose beginning should be parsed.
    Returns:
      A `Date` parsed from the string.
    Throws:
      `ParseException` - if the beginning of the specified string cannot be parsed.

  - ### parse

    Date parse(String source, ParsePosition pos)
    Equivalent to DateFormat.parse(String, ParsePosition). See `DateFormat.parse(String, ParsePosition)` for more information.
    Parameters:
      `source` - A `String`, part of which should be parsed.
      `pos` - A `ParsePosition` object with index and error index information as described above.
    Returns:
      A `Date` parsed from the string. In case of error, returns null.
    Throws:
      `NullPointerException` - if text or pos is null.

  - ### parse

    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` - 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:
      `IllegalArgumentException` - when Calendar has been set to be not lenient, and a parsed field is out of range.
    Since:
      3.5

  - ### parseObject

    Object parseObject(String source) throws ParseException
    Parses text from a string to produce a Date.
    Parameters:
      `source` - A `String` whose beginning should be parsed.
    Returns:
      a `Date` object.
    Throws:
      `ParseException` - if the beginning of the specified string cannot be parsed.
    See Also:
      - `Format.parseObject(String)`

  - ### parseObject

    Object parseObject(String source, ParsePosition pos)
    Parses a date/time string according to the given parse position.
    Parameters:
      `source` - A `String` whose beginning should be parsed.
      `pos` - the parse position.
    Returns:
      a `Date` object.
    See Also:
      - `DateFormat.parseObject(String, ParsePosition)`