Java--niit-ch2--location Localization Issues

Source: Internet
Author: User
Tags dateformat locale

Localizing Data:

gettimeinstance--represents time
1  PackageCHAP2;2 3 ImportJava.text.DateFormat;4 Importjava.util.Date;5 ImportJava.util.Locale;6 7  Public classDatademo {8      Public Static voidMain (string[] args) {9DateFormat df=dateformat.gettimeinstance (Dateformat.long,NewLocale ("de", "de"));TenString Date =df.format (NewDate ()); One System.out.print (date); A          -          -     } the}

getdateinstance--represents the date:
1  PackageCHAP2;2 3 ImportJava.text.DateFormat;4 Importjava.util.Date;5 ImportJava.util.Locale;6 7  Public classDatademo {8      Public Static voidMain (string[] args) {9DateFormat df=dateformat.getdateinstance (Dateformat.long,NewLocale ("de", "de"));TenString Date =df.format (NewDate ()); One System.out.print (date); A          -          -     } the}

Localizing Currency:

1  PackageCHAP2;2 3 ImportJava.text.NumberFormat;4 ImportJava.util.Locale;5 6  Public classCurrencydemo {7     Static intnumber=1000000;8      Public Static voidMain (String args[]) {9NumberFormat NFT =numberformat.getcurrencyinstance (NewLocale ("de", "de"));TenString formatted =Nft.format (number); One System.out.println (formatted); A          -     } -  the}

Localizing Text:
1. Create 2 files First (New-file):

File One: Name:

Messagebundle_de.properties

File Two: Name:

Messagebundle_zn.properties
1  PackageCHAP2;2 3 ImportJava.util.*;4 5  Public classTestlocale {6      Public Static voidMain (String args[]) {7Locale l1=NewLocale ("de", "de");8ResourceBundle rb1=resourcebundle.getbundle ("CHAP2. Messagebundle ", L1);9System.out.println (rb1.getstring ("message")); TenLocale l2=NewLocale ("Zn", "Zn"); OneResourceBundle rb2=resourcebundle.getbundle ("CHAP2. Messagebundle ", L2); ASystem.out.println (rb2.getstring ("message")); -          -     } the}

Note: ResourceBundle rb1=resourcebundle.getbundle ("CHAP2. Messagebundle ", L1);

To write: "CHAP2. Messagebundle "

Java--niit-ch2--location Localization Issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.