DateFormat format = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA);
String str = format.format(new Date());
解析页面中的字符串
FULL 和 LONG 和 MEDIUM 和 SHORT 的 区别
DataFomat
String format(Date date)
Date parse(String source)
创建static string2Date(String str)
分析区域
Locale locale = Locale.CHINA;
分析日期的风格
int dateType = DateFormat.SHORT;
int timeType = DateFormat.FULL;
获取对象
DateFormat format = DateFormat.getDateTimeInstance(dateType,timeType,locale);
解析
format.parse(str);
动态数字国际化
java.text.*;Number类NumberFormat(普通数字,货币,百分比)getIntegetInstancegetCurrencyInstancegetPercentInstance(Locale inLocale)formatparse创建cn.itcast.i18n.MyNumberI18n# 获取对象# getPercentInstance# getCurrencyInstanceNumberFormat format = NumberFormat.getIntegerInstance(Locale.CHINA);# 格式化 或解析long num = 10000000000L;# Number num = format.parse(str);# double price = num.doubleValue();format.format(num);
动态文本国际化
At 12:30 pm on jul 3,1998, a hurricance destroyed 99 houses and caused $1000000 of damage.MessageFormatMessageFormat(String pattern,Locale locale)format(String pattern,Object...arguments)format(Object)parse()占位At{0} on {0}, a hurricance destroyed{1} houses and caused {2} of damage.实例1:MyMessageI18n.java# 定义模式字符串String pattern# 定义locale对象MessageFormat format = new MessageFormat(pattern,Locale.CHINA);# 定义参数数组DateFormat datef = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT,Locale.US);Date date = datef.parse("Jul 3,1998 12:30 PM");Integer num = new Integer(99);long currency = NumberFormat.getCurrencyInstance(Locale.US).parse("$1000000");String damage = NumberFormat.getCurrencyInstance(locale).format(currency);Object [] values = {date,num,damage};# 格式化String str = format.format(values);分析:{索引,对象,类型}MessageFormat messf = new MessageFormat("{0,time,short} on {0,date}, a hurricance destroyed {1} houses and caused {2,number,currency} of damage.",Locale.CHINA);Object [] values = {new Date(),new Integer(100),1000};String str = messf.format(values);