首页 > 编程语言 > 详细

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

时间:2018-03-22 10:39:01      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:text   AC   println   local   util   pro   new   stl   创建   

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"

 

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

标签:text   AC   println   local   util   pro   new   stl   创建   

原文:https://www.cnblogs.com/Catherinezhilin/p/8621491.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号