Using the Locale.Category enumeration to display information using two different locales : Locale « JDK 7 « Java






Using the Locale.Category enumeration to display information using two different locales

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

public class Test {

  public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    Calendar calendar = Calendar.getInstance();
    calendar.setWeekDate(2012, 16, 3);

    System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG,
        DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

    Locale.setDefault(Locale.Category.FORMAT, Locale.JAPANESE);
    Locale.setDefault(Locale.Category.DISPLAY, Locale.GERMAN);

    System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG,
        DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

  }
}

 








Related examples in the same category

1.Handling locales and the Locale.Builder class in Java 1.7
2.Create Locale with Locale Builder
3.Create Locale from Language