As part of Internationalisation, got a requirement to support few countries like
Antigua and Barbuda - ISO3166 code - AG & Dominican Republic - ISO3166 code - DO
Locale loc = new Locale("en", "AG");
DateFormat df1 = DateFormat.getDateInstance(DateFormat.SHORT, loc);
System.out.println("Short format: " + df1.format(new Date()));
Java will display date in format mm/dd/yy, where as date format in those countries are dd/mm/yy.
Is there any way we can achieve the pattern dd/mm/yy? Even ICU4J libraries also not supporting those countries?
Thanks in advance
You can add additional locales to the Java runtime by creating an extension based on the appropriate service provider interface (SPI).
For example, if you wanted to specify the short date format for Antigua and Barbuda (en_AG), you can implement the
java.text.spi.DateFormatProviderSPI as follows:This will need to be packaged in a JAR file, and in the
META-INF/servicesdirectory of the JAR, you will need to create a file namedjava.text.spi.DateFormatProvider. That file needs to contain the fully qualified name of your provider, in my case just:Once you have created the JAR, you need to drop it in the extensions directory of your JRE. On my Ubuntu machine this happens to be
/usr/lib/jvm/java-8-oracle/jre/lib/ext/.After that, the code snippet from your question:
Will print out:
References: