Javaweb เป็นสากล
DateFormat: คลาสเครื่องมือที่จัดรูปแบบวันที่ซึ่งตัวเองเป็นคลาสนามธรรม;
NumberFormat: คลาสอักขระที่จัดรูปแบบตัวเลขเป็นสตริงตัวเลขหรือสตริงสกุลเงิน
MessageFormat: คุณสามารถจัดรูปแบบสตริงรูปแบบสตริงรูปแบบ: สตริงที่มีตัวยึดตำแหน่ง: "วันที่: {0}, เงินเดือน: {1}" คุณสามารถจัดรูปแบบสตริงรูปแบบผ่านวิธีการจัดรูปแบบ
ResourceBundle: คลาสแพ็คเกจทรัพยากรไฟล์ทรัพยากรที่เกี่ยวข้องจะต้องรวมอยู่ภายใต้ ClassPath (SRC): basename.properties ที่ basename คือชื่อพื้นฐาน;
ชื่อไฟล์คือ: test_zh_cn.properties, ไฟล์คือ: วันที่ =/u65e5/u671f, เงินเดือน =/u5de5/u8d44
ชื่อไฟล์คือ: test_en_us.properties ไฟล์คือ: วันที่ = วันที่, เงินเดือน = เงินเดือน
นำเข้า java.text.dateFormat; นำเข้า java.text.messageformat; นำเข้า java.text.numberformat; นำเข้า java.text.parseException; นำเข้า java.text.simpledateFormat; นำเข้า Java.util.date; i18ntest { /*** ResourceBundle: คลาสแพ็คเกจทรัพยากร * * 1. มีไฟล์ทรัพยากรที่สอดคล้องกันภายใต้ classpath: basename.properties ที่ basename เป็นชื่อพื้นฐาน * 2. คุณสามารถใช้รหัส NAME_LANGUAGE CODE_COUNTRY BASE.Properties เพื่อเพิ่มไฟล์ทรัพยากรจากประเทศหรือภูมิภาคต่างๆ i18n_zh_cn.properties * 3 จำเป็นต้องใช้คีย์ของไฟล์ทรัพยากรทั้งหมดที่มีชื่อพื้นฐานเดียวกันต้องเหมือนกันทุกประการ * 4. คุณสามารถใช้คำสั่ง Native2ASCII เพื่อรับรหัส ASC ของคู่อักขระจีน Eclipse มีเครื่องมือในตัว* 5. คุณสามารถโทรหา GetBundle (ชื่อพื้นฐาน, อินสแตนซ์โลคัล) ของ ResourceBundle เพื่อรับวัตถุ ResourceBundle* 6 คุณสามารถเรียก GetString (คีย์) ของ ResourceBundle เพื่อรับสตริงค่าของไฟล์ทรัพยากร * 7. รวมกับ DateFormat, NumberFormat, MessageFormat สามารถบรรลุความเป็นสากล * */ @Test โมฆะสาธารณะ TestResourceBundle () {locale locale = locale.china; ResourceBundle ResourceBundle = ResourceBundle.getBundle ("ทดสอบ", locale); System.out.println (ResourceBundle.getString ("วันที่")); System.out.println (ResourceBundle.getString ("เงินเดือน")); String DatelAbel = ResourceBundle.getString ("วันที่"); String Sallabel = ResourceBundle.getString ("เงินเดือน"); string str = "{0}: {1}, {2}: {3}"; วันที่วันที่ = วันที่ใหม่ (); Double Sal = 12345.12; DateFormat DateFormat = DateFormat.getDateInstance (DateFormat.medium, locale); String datestr = dateformat.format (วันที่); numberFormat numberFormat = numberFormat.getCurrencyInstance (locale); สตริง salstr = numberformat.format (sal); String result = messageFormat.format (str, datelabel, datestr, sallabel, salstr); System.out.println (ผลลัพธ์); } / *** MessageFormat: คุณสามารถจัดรูปแบบสตริงรูปแบบ* สตริงรูปแบบ: สตริงที่มีตัวยึดตำแหน่ง: "วันที่: {0}, เงินเดือน: {1}"* สตริงรูปแบบสามารถจัดรูปแบบผ่านวิธีการจัดรูปแบบ* / @Test Public Void TestMessageFormat () {String str = "วันที่: {0}, เงินเดือน: locale locale = locale.china; วันที่วันที่ = วันที่ใหม่ (); Double Sal = 12345.12; DateFormat DateFormat = DateFormat.getDateInstance (DateFormat.medium, locale); String datestr = dateformat.format (วันที่); numberFormat numberFormat = numberFormat.getCurrencyInstance (locale); สตริง salstr = numberformat.format (sal); String result = messageFormat.format (str, datestr, salstr); System.out.println (ผลลัพธ์); } /*** numberFormat: คลาสเครื่องมือสำหรับการจัดรูปแบบตัวเลขไปยังสตริงตัวเลขหรือสตริงสกุลเงิน* 1. รับวัตถุ NumberFormat ผ่านวิธีการเป็นโรงงาน* numberFormat.getNumberInstance (locale); // สตริงที่จัดรูปแบบเป็นตัวเลข* numberFormat.getCurrencyInstance (locale); // สตริงที่จัดรูปแบบเป็นสกุลเงิน** 2. วิธีการจัดรูปแบบ* 3. แยกวิเคราะห์สตริงลงในประเภทตัวเลขผ่านวิธีการแยกวิเคราะห์ */ @Test โมฆะสาธารณะ testNumberFormat () พ่น parseexception {double d = 123456789.123d; locale locale = locale.france; // numberFormat numberFormat = numberFormat.getNumberInstance (locale); string str = numberFormat.format (d); System.out.println (str); numberFormat numberFormat2 = numberFormat.getCurrencyInstance (locale); str = numberFormat2.format (d); System.out.println (str); str = "123 456 789,123"; d = (double) numberFormat.parse (str); System.out.println (D); str = "123 456 789,12; d = (double) numberFormat2.parse (str); system.out.println (d);} / * * 7. ถ้ามีสตริงวิธีการแยกวิเคราะห์ลงในวัตถุวันที่ YYYY-MM-DD HH: MM: SS * II DateFormat.parse (STR); Alocale) * 3. คุณสามารถรับวัตถุวันที่ที่มีเพียงรูปแบบเวลา: getTimeInstance (สไตล์ int, locale alocale) * 4. คุณสามารถรับวัตถุวันที่ที่จัดรูปแบบทั้งวันและเวลา: * getDateTimeInstance Locale เป็นวัตถุในสถานที่ที่เป็นตัวแทนของประเทศและภูมิภาค* 6. จัดรูปแบบวัตถุวันที่เป็นสตริงผ่านวิธีการจัดรูปแบบของ dateformat */ @Test Public Void TestDateFormat () {locale locale = locale.us; วันที่วันที่ = วันที่ใหม่ (); System.out.println (วันที่); // รับ dateformat object dateformat dateformat = dateformat.getDateTimeInstance (dateformat.long, dateformat.medium, locale); string str = dateformat.format (วันที่); System.out.println (str); } /*** locale: คลาสที่แสดงถึงประเทศหรือภูมิภาคใน Java ค่าคงที่จำนวนมากมีอยู่ใน JDK * คุณยังสามารถสร้างผ่าน Locale (LanguageCode, CountryCode) * ในเว็บแอปพลิเคชันคุณสามารถรับมันผ่านวิธีการ request.getLocale () */ @Test โมฆะสาธารณะ testLocale () {locale locale = locale.china; System.out.println (locale.getDisplayCountry ()); System.out.println (locale.getLanguage ()); locale = locale ใหม่ ("en", "us"); System.out.println (locale.getDisplayCountry ()); System.out.println (locale.getLanguage ()); -ข้างต้นเป็นการรวบรวมความเป็นสากลของเว็บ Java เราจะยังคงเพิ่มข้อมูลที่เกี่ยวข้องในอนาคต ขอบคุณสำหรับการสนับสนุนเว็บไซต์นี้!