Class AnyDateParser


  • public class AnyDateParser
    extends Object
    Parses strings containing dates in almost any known international format.
    Author:
    Michel Kraemer
    • Constructor Detail

      • AnyDateParser

        public AnyDateParser()
    • Method Detail

      • parse

        public static TemporalAccessor parse​(String date)
                                      throws IllegalArgumentException
        Parse a string containing a date in almost any known international format. Parses at most year, month, and date and returns them in a TemporalAccessor object. This object may not contain all fields if the string does not contain them as well. For example, if the string is "2014-10", the object will only contain a year and a month but not a day.
        Parameters:
        date - the string containing the date
        Returns:
        the parsed date
        Throws:
        IllegalArgumentException - if the date could not be parsed
      • parse

        public static TemporalAccessor parse​(String date,
                                             Locale locale)
                                      throws IllegalArgumentException
        Parse a string containing a date in almost any known international format. Parses at most year, month, and date and returns them in a TemporalAccessor object. This object may not contain all fields if the string does not contain them as well. For example, if the string is "2014-10", the object will only contain a year and a month but not a day.
        Parameters:
        date - the string containing the date
        locale - the locale to use for parsing (used to parse month names and to determine if the locale prefers the month to be given before the day in the string to parse or the other way around)
        Returns:
        the parsed date
        Throws:
        IllegalArgumentException - if the date could not be parsed