fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.time.*;
  6. import java.time.format.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. printDate(new Locale("pt", "BR"));
  15. printDate(new Locale("pt", "PT"));
  16. printDate(new Locale("ar", "DZ"));
  17. printDate(new Locale("it", "IT"));
  18. }
  19. static void printDate(Locale locale) {
  20. System.out.println("Locale: " + locale);
  21. for (FormatStyle style : Arrays.asList(FormatStyle.MEDIUM, FormatStyle.SHORT)) {
  22. DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(style).withLocale(locale);
  23. System.out.printf("%7s %s\n", style, formatter.format(LocalDate.now()));
  24. }
  25. }
  26. }
Success #stdin #stdout 0.21s 41600KB
stdin
Standard input is empty
stdout
Locale: pt_BR
 MEDIUM 27 de mai de 2020
  SHORT 27/05/2020
Locale: pt_PT
 MEDIUM 27/05/2020
  SHORT 27/05/20
Locale: ar_DZ
 MEDIUM 27‏/05‏/2020
  SHORT 27‏/5‏/2020
Locale: it_IT
 MEDIUM 27 mag 2020
  SHORT 27/05/20