Java Locale create from constructor

Description

Java Locale create from constructor

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

public class Main {

   public static void main(String[] args) {
      String[][] langRegions = { { "fr", "FR" }, { "ja", "JP" }, { "en", "US" } };
      Locale l = null;/* w  w w  .j  a va 2 s  . com*/
      for (String[] a : langRegions) {
         // a[0] is ISO 639 language code, a[1] is an ISO 3166 region
         l = new Locale(a[0], a[1]);
         displayLocalizedData(l);
      }
   }

   private static void displayLocalizedData(Locale l) {
      long number = 123456789L;
      Date date = new Date();

      NumberFormat nf = NumberFormat.getInstance(l);
      DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, l);
      System.out.printf("Locale: %s\nNumber: %s\nDate: %s\n\n", l.getDisplayName(), nf.format(number), df.format(date));
   }
}



PreviousNext

Related