fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.MessageFormat;
  7. import java.text.FieldPosition;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. Locale portugal = new Locale("pt");
  15. Locale brazil = new Locale("pt", "BR");
  16. Locale france = new Locale("fr", "FR");
  17.  
  18. Object[] params = new Object[] {new Date()};
  19. String pattern = "Today is {0,date,long}!";
  20.  
  21. MessageFormat ptFormat = new MessageFormat(pattern, portugal);
  22. MessageFormat brFormat = new MessageFormat(pattern, brazil);
  23. MessageFormat frFormat = new MessageFormat(pattern, france);
  24.  
  25. StringBuffer ptResult = ptFormat.format(params, new StringBuffer(), new FieldPosition(0));
  26. StringBuffer brResult = brFormat.format(params, new StringBuffer(), new FieldPosition(0));
  27. StringBuffer frResult = frFormat.format(params, new StringBuffer(), null);
  28.  
  29. System.out.println("Portugal result: " + ptResult.toString());
  30. System.out.println("Brazil result: " + brResult.toString());
  31. System.out.println("France result: " + frResult.toString());
  32. }
  33. }
Success #stdin #stdout 0.15s 30784KB
stdin
Standard input is empty
stdout
Portugal result: Today is July 10, 2018!
Brazil result: Today is July 10, 2018!
France result: Today is July 10, 2018!