Java--Niit-ch2--Location本地化问题

Localizing Data:

getTimeInstance--表示时间
 1 package CHAP2;
 2 
 3 import java.text.DateFormat;
 4 import java.util.Date;
 5 import java.util.Locale;
 6 
 7 public class DataDemo {
 8     public static void main(String[] args) {
 9         DateFormat df=DateFormat.getTimeInstance(DateFormat.LONG, new Locale("de","DE"));
10                 String date =df.format(new Date());
11         System.out.print(date);
12         
13         
14     }
15 }

getDateInstance--表示日期:
 1 package CHAP2;
 2 
 3 import java.text.DateFormat;
 4 import java.util.Date;
 5 import java.util.Locale;
 6 
 7 public class DataDemo {
 8     public static void main(String[] args) {
 9         DateFormat df=DateFormat.getDateInstance(DateFormat.LONG, new Locale("de","DE"));
10                 String date =df.format(new Date());
11         System.out.print(date);
12         
13         
14     }
15 }

 

 

Localizing Currency:

 1 package CHAP2;
 2 
 3 import java.text.NumberFormat;
 4 import java.util.Locale;
 5 
 6 public class CurrencyDemo {
 7     static int number=1000000;
 8     public static void main(String args[]) {
 9         NumberFormat nft =NumberFormat.getCurrencyInstance(new Locale ("de","DE"));
10         String formatted =nft.format(number);
11         System.out.println(formatted);
12         
13     }
14 
15 }

Localizing Text:
1.先创建2个文件(new-file):

文件一:命名:

MessageBundle_de.properties

文件二:命名:

MessageBundle_zn.properties
 1 package CHAP2;
 2 
 3 import java.util.*;
 4 
 5 public class TestLocale {
 6     public static void main(String args[]) {
 7         Locale l1=new Locale("de","DE");
 8         ResourceBundle rb1=ResourceBundle.getBundle("CHAP2.MessageBundle",l1);
 9         System.out.println(rb1.getString("message"));    
10         Locale l2=new Locale("zn","ZN");
11         ResourceBundle rb2=ResourceBundle.getBundle("CHAP2.MessageBundle",l2);
12         System.out.println(rb2.getString("message"));
13         
14     }
15 }

注:ResourceBundle rb1=ResourceBundle.getBundle("CHAP2.MessageBundle",l1);

要写:"CHAP2.MessageBundle"

 

转载于:https://www.cnblogs.com/Catherinezhilin/p/8621491.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值