Create Locale from Language
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
public class Test {
public static void main(String[] args) {
long SAMPLE_NUMBER = 123456789L;
Date NOW = new Date();
System.out.printf("Creating from BCP 47 language tags...\n\n");
String[] bcp47LangTags= {"fr-FR", "ja-JP", "en-US"};
Locale l = null;
for (String langTag: bcp47LangTags) {
l = Locale.forLanguageTag(langTag);
displayLocalizedData(l, SAMPLE_NUMBER, NOW);
}
}
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 examples in the same category