Class MultiFormatDateParser


  • public class MultiFormatDateParser
    extends Object
    Attempt to parse date strings in a variety of formats. This uses an external list of regular expressions and associated SimpleDateFormat strings. Inject the list as pairs of strings using setPatterns(java.util.Map<java.lang.String, java.lang.String>). parse(java.lang.String) walks the provided list in the order provided and tries each entry against a String. Dates are parsed as being in the UTC zone.
    Author:
    mwood
    • Constructor Detail

      • MultiFormatDateParser

        public MultiFormatDateParser()
    • Method Detail

      • setPatterns

        @Inject
        public void setPatterns​(Map<String,​String> patterns)
      • parse

        public static Date parse​(String dateString)
        Compare a string to each injected regular expression in entry order, and when it matches, attempt to parse it using the associated format.
        Parameters:
        dateString - the supposed date to be parsed.
        Returns:
        the result of the first successful parse, or null if none.