1.Local
java.util.Locale是表示语言和国家地区信息的本地化类,他是创建国际化应用的基础。
public class Test1 {
public static void main(String args[]){
Locale locale1= new Locale("zh","CN");
Locale locale2= new Locale("zh");
Locale locale3= Locale.CHINA;
Locale locale4=Locale.CHINESE;
//获取本地系统默认的本地化对象
Locale locale5= Locale.getDefault();
}
}
2.本地化工具类
JDK的java.util包中提供了几个支持本地化的格式化操作工具类:NumberFormat,DateFormat,MessageFormat。
1)NumberFormat
Locale loacle= new Locale("zh","CN");
NumberFormat currFmt=NumberFormat.getCurrencyInstance(loacle);
double amt=123456.78;
System.out.println(currFmt.format(amt));
2)DateFormat
Locale locale= new Locale("en","US");
Date date= new Date();
DateFormat df= DateFormat.getDateInstance(DateFormat.MEDIUM,locale);
System.out.println(df.format(date));
3)MessageFormat在NumberFormat和DateFormat的基础上提供了强大的占位符字符串的格式化功能,它支持时间、货币、数字以及对象属性的格式化操作。