You are using the troublesome old date-time classes, now legacy, supplanted by the java.time classes.
Antigua and Barbuda
“Antigua and Barbuda - ISO3166 code - AG” is not a supported locale in Java 8. See the list of supported locales or call:
System.out.println ( "locales: " + Arrays.toString ( Locale.getAvailableLocales () ) );
You can build your own list of explicit formatting patterns for such unsupported locales. For example, DateTimeFormatter.ofPattern( "dd/MM/yy" )
.
Better yet, define a Map
of each undefined locale using language-country string such as "en-AG" to a similar defined Locale
that uses the same appropriate formats.
Or define an Enum
for each undefined locale with methods that return DateTimeFormatter
objects for each length (FULL, SHORT etc.).
Or consider the Answer by Comelissen, though I have not studied that well enough to recommend it yet.
Dominican Republic
“Dominican Republic - ISO3166 code - DO” is supported in Java 8.
Locale locale = new Locale ( "es" , "DO" ); // Spanish in Dominican Republic.
LocalDate localDate = LocalDate.now ( ZoneId.of ( "Europe/Paris" ) );
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate ( FormatStyle.SHORT ).withLocale ( locale );
String output = localDate.format ( f );
System.out.println ( "localDate: " + localDate + " is " + output );
localDate: 2017-02-16 is 16/02/17
The result is as you desired, dd/MM/yy.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8 and SE 9 and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.