Java Reference
In-Depth Information
// Print the locale info
System.out.println("Language: " + languageName + "(" +
languageCode + "); " +
"Country: " + countryName +
"(" + countryCode + ")");
}
public static void printDate (Locale locale, Date date){
DateFormat formatter;
String formattedDate;
// Format and print the date in SHORT style
formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
formattedDate = formatter.format(date);
System.out.println("SHORT: " + formattedDate);
// Format and print the date in MEDIUM style
formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
formattedDate = formatter.format(date);
System.out.println("MEDIUM: " + formattedDate);
// Print a blank line at the end
System.out.println();
}
}
Language: English(en); Country: United States(US)
SHORT: 1/24/14
MEDIUM: Jan 24, 2014
Language: French(fr); Country: France(FR)
SHORT: 24/01/14
MEDIUM: 24 janv. 2014
Language: German(de); Country: Germany(DE)
SHORT: 24.01.14
MEDIUM: 24.01.2014
The java.util.Locale class contains constants for some common locales For example, you can use
Locale.FRANCE for a locale with language "fr" and country code "FR" . Alternatively, you can create a locale object
for France like so:
Locale frenchLocale = new Locale("fr", "FR") ;
To create a Locale , you need to use a two-letter lowercase language code and a two-letter uppercase country
code if the Locale class does not declare a constant for that country. Language codes and country codes have been
listed in ISO-639 code and ISO-3166 code. Some more examples of creating locales are as follows:
Locale hindiIndiaLocale = new Locale("hi", "IN");
Locale bengaliIndiaLocale = new Locale("bn", "IN");
Locale thaiThailandLocale = new Locale("th", "TH");
 
Search WWH ::




Custom Search