Open zuiliushang opened 8 years ago
例如:
public static void main(String[] args){
Date date = new Date(); //当前这一刻时间(日期,时间)
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL,Locale.CHINA);
String result = dateFormat.format(date);
System.out.println(result);
dateFormat = DateFormat.getTimeInstance(dateFormat.FULL, Locale.CHINA);
result = dateFormat.format(date);
System.out.println(result);
dateFormat = DateFormat.getDateTimeInstance(dateFormat.FULL,
dateFormat.SHORT,Locale.CHINA);
result = dateFormat.format(date);
System.out.println(result);
}
方法:
public static void main(String[] args) throws Exception{
int price = 50;
NumberFormat nFormat = NumberFormat.getCurrencyInstance(Locale.CHINA);
String a = nFormat.format(price);
System.out.println(a);
}
format(object obj[]) 格式化输出模式字符串,参数数组中制定占位符相应的替换对象。
format(new Object[]{date,new Integer(99),new Double(1E7)})
public static void main(String[] args) throws Exception{
String pattern = "on {0}, a hurricance destroyed {1} houses and caused {2} of damage";
MessageFormat messageFormat = new MessageFormat(pattern,Locale.CHINA);
Object[] arr = {new Date(),99,1000000};
String result = messageFormat.format(arr);
System.out.println(result);
}
public static void main(String[] args) throws Exception{
String pattern = "At {0,time,short} on {0,date}, a hurricance destroyed {1} houses and
caused {2,number,currency} of damage";
MessageFormat messageFormat = new MessageFormat(pattern,Locale.CHINA);
Object[] arr = {new java.util.Date(),99,10000000};
String result = messageFormat.format(arr);
System.out.println(result);
}
固定文本元素的国际化
创建资源包和资源文件
myproperites_zh.properties
myproperites_en.properties
myproperites.propertiese
资源文件的书写格式
属性文件是不能保存中文的
编程实现固定文本的国际化
java String value = myResources.getString("key");