3

I'm trying to support dates in different locales. At the moment all is working fine with the FormatStyle.SHORT.

DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(someDynamicLocale);

The problem is that the year field is only 2 digits long. If I try to parse this string "22/10/84" in which century are we?

I can use the other formats (MEDIUM, LONG, FULL) but in all of this formats the month is a text instead of a number, and in my application is not applicable.

For this reason my dream is only to customize the SHORT format setting the length of the year field to 4 digits.

Is it possible? Can the DateTimeFormatterBuilder help me?

Martin Nyolt
  • 4,463
  • 3
  • 28
  • 36
Gavi
  • 1,300
  • 1
  • 19
  • 39

1 Answers1

0

You can try DateTimeFormatterBuilder, for example if you want the format "d.M.yyyy". you can use:

String datePattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(
  FormatStyle.SHORT, null, IsoChronology.INSTANCE, 
  Locale.SPAIN); 

here is a simmilar post How do I get localized date pattern string?

Community
  • 1
  • 1
El0din
  • 3,208
  • 3
  • 20
  • 31