Create Locales with Locale constructor - Java Internationalization

Java examples for Internationalization:Locale

Description

Create Locales with Locale constructor

Demo Code

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

public class Main {
  public static void main(String[] a) {

    String[][] langRegions = { { "fr", "FR" }, { "ja", "JP" }, { "en", "US" } };
    Locale l = null;/*w  w  w .  j  av  a 2s  .  co  m*/
    for (String[] args : langRegions) {
      l = new Locale(args[0], args[1]);
      displayLocalizedData(l, 123456789L, new Date());
    }
  }

  private static void displayLocalizedData(Locale l, long number, Date 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));
  }
}

Related Tutorials