Java Reference
In-Depth Information
Another way to create Locale instances is by using the static
Locale.forLanguageTag() method. This method allows you to use BCP 47 lan-
guage tag arguments. The following code uses the forLanguageTag() method to
create three locales from their corresponding language tags:
...
System.out.printf("Creating from BCP 47 language
tags...\n\n");
String[] bcp47LangTags= {"fr-FR", "ja-JP", "en-US"};
Locale l = null;
NumberFormat nf = null;
DateFormat df = null;
for (String langTag: bcp47LangTags) {
l = Locale.forLanguageTag(langTag);
nf = NumberFormat.getInstance(l);
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(now));
}
...
The output is similar to the results created from the Builder -generated Locale
instance:
Creating from BCP 47 language tags...
Locale: French (France)
Number: 123 456 789
Date: 14 septembre 2011 01:07:22 PDT
...
You can also use constructors to create instances. The following code shows how to
do this:
Locale l = new Locale("fr", "FR");
Search WWH ::




Custom Search