Is there a way to get Joda's time to analyze dates only when they contain four digits of years? For instance:
- 2009-11-11 - must understand
- 09-11-11 - do not understand
Tried the following code:
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeFormatter formatter = builder.appendYear(4, 4).appendLiteral('-').appendMonthOfYear(1).appendLiteral('-').appendDayOfMonth(1).toFormatter(); formatter.parseDateTime("09-11-11");
Parses in 0009-11-11. Apparently, minDigits in the appendYear method are used only for formatting when printing a date.
The result is the same if I use appendYearOfEra (). If I use appendYearOfCentury (), it analyzes the year in 1909.
We implement a common data analyzer that will recognize various types of inputs. Another example is a shortened form of a real transaction (for simplicity). Real-life scenarios analyze dates that may have days of the week, months as words, time, zone, and various characters separating the month, day, and year. Therefore, writing RegEx or checking the contents / line length can be quite complicated.
Some real examples might look like this:
- 2009-11-11
- Wednesday 2009-11-11T15: 00: 00
- 2009/11/11 15:00
- and much more...
source share