The accepted Answer by Ole V.V. is correct.
Peruse all localized formats
If you want to peruse all the localized formats for all the known time zones, here is some code to dump example values to console.
Use DateTimeFormatter
to automatically localize. To localize, specify:
FormatStyle
to determine how long or abbreviated should the string be.
Locale
to determine (a) the human language for translation of name of day, name of month, and such, and (b) the cultural norms deciding issues of abbreviation, capitalization, punctuation, separators, and such.
Example:
Locale locale = Locale.CANADA_FRENCH ;
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL ).withLocale( locale );
String output = localDate.format( f );
Specify all format styles.
EnumSet.allOf( FormatStyle.class )
[FULL, LONG, MEDIUM, SHORT]
Collect the Locale
objects you want to try. You could get a list of all known locales.
Locale[] locales = Locale.getAvailableLocales();
Or specify just a few locales.
List < Locale > locales = new ArrayList <>( 3 );
locales.add( Locale.CANADA_FRENCH ); // French, Québec Canada
locales.add( new Locale( "ga" , "IE" ) ); // Irish, Ireland
locales.add( new Locale( "en" , "IE" ) ); // English, Ireland
locales.add( Locale.US ); // English, United States
Complete example code.
LocalDate ld = LocalDate.of( 2018 , Month.MARCH , 23 );
List < Locale > locales = new ArrayList <>( 3 );
locales.add( Locale.CANADA_FRENCH );
locales.add( new Locale( "ga" , "IE" ) );
locales.add( new Locale( "en" , "IE" ) );
locales.add( Locale.US );
for ( Locale locale : locales )
{
System.out.println( "------| LOCALE: " + locale + " — " + locale.getDisplayName() + " |----------------------------------" + System.lineSeparator() );
for ( FormatStyle style : EnumSet.allOf( FormatStyle.class ) )
{
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( style ).withLocale( locale );
String output = ld.format( f );
System.out.println( output );
}
System.out.println( "" );
}
System.out.println( "« fin »" + System.lineSeparator() );
Output for our few locales.
------| LOCALE: fr_CA — French (Canada) |----------------------------------
vendredi 23 mars 2018
23 mars 2018
23 mars 2018
18-03-23
------| LOCALE: ga_IE — Irish (Ireland) |----------------------------------
Dé hAoine 23 Márta 2018
23 Márta 2018
23 Márta 2018
23/03/2018
------| LOCALE: en_IE — English (Ireland) |----------------------------------
Friday 23 March 2018
23 March 2018
23 Mar 2018
23/03/2018
------| LOCALE: en_US — English (United States) |----------------------------------
Friday, March 23, 2018
March 23, 2018
Mar 23, 2018
3/23/18
« fin »
Output for first 8 of all 736 locales (in Java 9.0.4). (The full content of about 120K in text is too much for Stack Overflow.)
------| LOCALE: — |----------------------------------
2018 Mar 23, Fri
2018 Mar 23
2018 Mar 23
2018-03-23
------| LOCALE: nn — Norwegian Nynorsk |----------------------------------
fredag 23. mars 2018
23. mars 2018
23. mars 2018
23.03.2018
------| LOCALE: ar_JO — Arabic (Jordan) |----------------------------------
الجمعة، 23 آذار، 2018
23 آذار، 2018
23/03/2018
23/3/2018
------| LOCALE: bg — Bulgarian |----------------------------------
петък, 23 март 2018 г.
23 март 2018 г.
23.03.2018 г.
23.03.18 г.
------| LOCALE: kea — Kabuverdianu |----------------------------------
sesta-fera, 23 di Marsu di 2018
23 di Marsu di 2018
23 Mar 2018
23/3/2018
------| LOCALE: zu — Zulu |----------------------------------
ULwesihlanu, Mashi 23, 2018
Mashi 23, 2018
Mas 23, 2018
3/23/18
------| LOCALE: am_ET — Amharic (Ethiopia) |----------------------------------
ዓርብ ፣23 ማርች 2018
23 ማርች 2018
23 ማርች 2018
23/03/2018
------| LOCALE: fr_DZ — French (Algeria) |----------------------------------
vendredi 23 mars 2018
23 mars 2018
23 mars 2018
23/03/2018
…