国际化(1)

1.TestI18n

import java.util.Locale;

public class TestI18n {

	public static void main(String[] args) {
		Locale locale=Locale.CHINA;
		System.out.println(locale.getCountry());
		System.out.println(locale.getLanguage());
		System.out.println("-------------------");
		locale=Locale.US;
		System.out.println(locale.getCountry());
		System.out.println(locale.getLanguage());
		System.out.println("-------------------");
		Locale l=new Locale("zh","CN");
		System.out.println(l.getDisplayCountry());

	}

}

2. TestDataFormat

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;



public class TestDataFormat {

	public static void main(String[] args) throws Exception {
		Date data=new Date();
		DateFormat df=DateFormat.getDateInstance(DateFormat.LONG, Locale.CHINA);
		//日期转化为字符串
		String source=df.format(data);
		System.out.println("***********************");
		System.out.println("DateFormat.LONG=  "+source);
		System.out.println("***********************");
		df=DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINA);
		//日期转化为字符串
		 source=df.format(data);
		System.out.println("***********************");
		System.out.println("DateFormat.MEDIUM= "+source);
		System.out.println("***********************");
		df=DateFormat.getDateInstance(DateFormat.SHORT, Locale.CHINA);
		//日期转化为字符串
		 source=df.format(data);
		System.out.println("***********************");
		System.out.println("DateFormat.SHORT= "+source);
		System.out.println("################################");
		//转化为日期.当字符串的格式不知道的情况下,先将日期转化为字符串,找到对应的格式做改动
		df=DateFormat.getDateInstance(DateFormat.SHORT, Locale.CHINA);
		System.out.println(df.format(new Date()));//12-10-24
		String dateStr="12-10-24";
		df=DateFormat.getDateInstance(DateFormat.SHORT, Locale.CHINA);
		Date d=df.parse(dateStr);
		System.out.println("转化为日期:  "+d);
		

	}

}

3. TestNumberFormat

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;


public class TestNumberFormat {

	public static void main(String[] args) throws Exception {
		Locale locale=Locale.CHINA;
		NumberFormat nf=NumberFormat.getInstance(locale);
		
		double num=123456789.78;
		//格式规范
		String src=nf.format(num);
		System.out.println(src);
		System.out.println("***********************");
		locale=Locale.FRANCE;
		nf=NumberFormat.getInstance(locale);
		src=nf.format(num);
		System.out.println(src);
		System.out.println("***********************");
		
		locale=Locale.CHINA;
		nf=NumberFormat.getInstance(locale);
		src="456,789.89";
		//解析给定字符串开头的文本,生成一个数值
		System.out.println(nf.parse(src));
	}

}

4. TestMessageFormat

import java.text.MessageFormat;


public class TestMessageFormat {

	public static void main(String[] args) {
		//String pattern=" I worked at dhc and good ";
		String pattern=" I {0} at {1} and {2} ";
		MessageFormat mf=new MessageFormat(pattern);
		//格式化一个对象数组,并将MessageFormat的模式添加到所提供的StringBuffer
		Object[] params=new Object[]{"worked","dhc","good"};
		StringBuffer buf=new StringBuffer();
		
		mf.format(params, buf, null);
		
		System.out.println(buf.toString());
		
	}

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值