First, the locale class
locale locale = Locale.china; Locale locale = new locale ("zh", "CN"); System.out.println (Locale.getlanguage ()); System.out.println (Locale.getdisplaycountry ()); System.out.println (Locale.getdisplaylanguage ());
Second, DateFormat class
Date date = new Date (); SYSTEM.OUT.PRINTLN (date); Locale locale = new locale ("zh", "cn");D Ateformat DateFormat = dateformat.getdateinstance (dateformat.full, locale); System.out.println (Dateformat.format (date)); String dates = "2017-3-17";D ateformat df = new SimpleDateFormat ("Yyyy-mm-dd"); System.out.println (Df.parse (dates));
Third, NumberFormat class
Double d = 1.12d; Locale locale = locale.china;//formatted as currency numberformat NumberFormat = numberformat.getcurrencyinstance (locale);// Formatted as a digital NumberFormat numberFormat2 = numberformat.getnumberinstance (locale);//formatted as a percentage numberformat NUMBERFORMAT3 = Numberformat.getpercentinstance (locale); System.out.println (Numberformat.format (d)); System.out.println (Numberformat2.format (d)); System.out.println (Numberformat3.format (d));
Four, Messageformat class
String str = "{0},{1}"; String STRs = Messageformat.format (str, "UserName", "admin"); System.out.println (STRs);
Five, ResourceBundle class
ResourceBundle bundle = Resourcebundle.getbundle ("i18n", New Locale ("en", "US"); System.out.println (bundle.getstring ("UserName"));
VI. International Resource Documents
I18n.properties Username=username
I18n_zh_cn.properties username=\u7528\u6237\u540d
I18n_en_us.properties Username=username
Note: i18n is the base name, en is the language code, CN is the country code
Vii. FMT tags for JSP pages
<%@ taglib prefix= "FMT" uri= "http://java.sun.com/jsp/jstl/fmt"%> <%locale locale = locale.us;//locale locale = Locale.china;request.setattribute ("locale", locale); System.out.println (Request.getlocale ());//print out all the resources configured in the application International file Enumeration<locale> enumeration = Request.getlocales (); while (Enumeration.hasmoreelements ()) {Locale locale2 = enumeration.nextelement (); System.out.println (locale2);} %><fmt:setlocale value= "${requestscope.locale}"/>${requestscope.locale}<fmt:setbundle basename= "i18n "/><fmt:message key=" UserName "></fmt:message><fmt:formatnumber type=" currency "value=" 123 "> </fmt:formatNumber>
This article is from the "11137669" blog, please be sure to keep this source http://11147669.blog.51cto.com/11137669/1907741
Java Web Internationalization