国际化开发类的实例

来源:互联网 发布:什么是网络剧 编辑:程序博客网 时间:2024/06/01 08:02
 

1、

public static void main(String[] args) {

       // TODO Auto-generated method stub

       Locale locale=new Locale("en");

       //ResourceBundle bundle=ResourceBundle.getBundle("com.hbsi.resource.MyResource");

       ResourceBundle bundle=ResourceBundle.getBundle("com.hbsi.resource.MyResource",locale);

       String username=bundle.getString("username");

       String password=bundle.getString("password");

       String submit=bundle.getString("submit");

       System.out.println(username+":"+password+":"+submit);

    }

2、时间转化

public static void main(String[] args) throws ParseException{

       Date d=new Date();

       DateFormat df=DateFormat.getDateInstance(DateFormat.FULL,Locale.CHINA);//获取时间格式器

       String result=df.format(d);

       System.out.println(result);

      

       String str="2011年11月4日 星期一";

       Date d1=df.parse(str);

       System.out.println(d1);

      

       df=DateFormat.getDateInstance(DateFormat.FULL,Locale.ENGLISH);//获取时间格式器

        result=df.format(d);

       System.out.println(result);

      

       df=DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.LONG,Locale.CHINA);//获取时间格式器

        result=df.format(d);

       System.out.println(result);

      

       NumberFormat nf=NumberFormat.getCurrencyInstance();

       double f=56.9;

       str=nf.format(f);

       System.out.println(str);

      

       NumberFormat nf1=NumberFormat.getPercentInstance(Locale.US);

       double f1=0.22;

       str=nf1.format(f1);

       System.out.println(str);

      

    }

3、文本转化

    public static void main(String[] args) {

       // TODO Auto-generated method stub

       //at

       String pattern="At {0},a hurricance {1}";

       MessageFormat mf=new MessageFormat(pattern,Locale.US);

       Object[] objs={new Date(),new Integer(99)};

       String result=mf.format(objs);

       System.out.println(result);

    }

原创粉丝点击