Use Locale with DateFormat


/*
 * Output:
Japan: 4/28/06
Korea: Apr 28, 2006
United Kingdom: 28 April 2006
United States: Friday, April 28, 2006
 * */

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

public class MainClass {
  public static void main(String args[]) {
    Date date = new Date();
    DateFormat df;

    df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN);
    System.out.println("Japan: " + df.format(date));

    df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.KOREA);
    System.out.println("Korea: " + df.format(date));

    df = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK);
    System.out.println("United Kingdom: " + df.format(date));

    df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
    System.out.println("United States: " + df.format(date));
  }
}
Home 
  Java Book 
    Essential Classes  

Locale:
  1. Locale class
  2. Locale.ITALY
  3. Use Locale with DateFormat
  4. new Locale(String language, String country, String variant)
  5. getDefault()
  6. getDisplayCountry()
  7. getDisplayCountry(Locale inLocale)
  8. getDisplayLanguage()
  9. getDisplayName()
  10. getDisplayVariant()
  11. getISOCountries()
  12. getISOLanguages()
  13. setDefault(Locale newLocale)