Class AnyDateParser


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

      Constructors 
      Constructor Description
      AnyDateParser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.time.temporal.TemporalAccessor parse​(java.lang.String date)
      Parse a string containing a date in almost any known international format.
      static java.time.temporal.TemporalAccessor parse​(java.lang.String date, java.util.Locale locale)
      Parse a string containing a date in almost any known international format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AnyDateParser

        public AnyDateParser()
    • Method Detail

      • parse

        public static java.time.temporal.TemporalAccessor parse​(java.lang.String date)
                                                         throws java.lang.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:
        java.lang.IllegalArgumentException - if the date could not be parsed
      • parse

        public static java.time.temporal.TemporalAccessor parse​(java.lang.String date,
                                                                java.util.Locale locale)
                                                         throws java.lang.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:
        java.lang.IllegalArgumentException - if the date could not be parsed