Java Locale create from constant

Description

Java Locale create from constant

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) {
      Locale[] locales = new Locale[]{Locale.FRANCE, Locale.JAPAN, Locale.US};        
      for (Locale l: locales) {
          displayLocalizedData(l);/*  w  ww . ja v  a2s .  c o  m*/
      }    
   }

   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