I need to parse the date string dynamically based on the locale and format style.
For example, I have an Albanian locale which has pattern yy-MM-dd
I have following code which resolves this pattern basing on the current locale and format style
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendLocalized(FormatStyle.SHORT, null)
.toFormatter()
.withLocale(Locale.forLanguageTag("sq-AL"));
TemporalAccessor temporalAccessor = formatter.parseBest("92-07-09", LocalDateTime::from, LocalDate::from, LocalTime::from);
System.out.println(temporalAccessor);
The input string is parsed as 09/07/2092
But I need to parse this date as 09/07/1992
Adding the code for .appendValueReduced
doesn't work
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendLocalized(FormatStyle.SHORT, null)
.appendValueReduced(ChronoField.YEAR, 2, 2, LocalDate.now().minusYears(80))
.toFormatter()
.withLocale(Locale.forLanguageTag("sq-AL"));
I've searched for answers on StackOverflow but did not find any that works without .appendPattern()
and based on the locale and format style
Thanks in advance!