Javaweb Internationalization
dateformat:日付をフォーマットするツールクラスは、それ自体が抽象クラスです。
NumberFormat:数値を数値文字列または通貨文字列に形成する文字クラス。
messageformat:パターン文字列、パターン文字列:プレースホルダーを備えた文字列: "date:{0}、salary:{1}"をフォーマットできます。フォーマットメソッドを使用してパターン文字列をフォーマットできます。
ResourceBundle:リソースパッケージクラス、対応するリソースファイルは、ClassPath(SRC):Basename.Propertiesに含める必要があります。 Basenameが基本名です。
ファイル名は:test_zh_cn.properties、ファイルは日付=/u65e5/u671f、salary =/u5de5/u8d44です。
ファイル名は:test_en_us.properties、ファイルは日付=日付、給与= salaryです
java.text.dateformat;インポートjava.text.messageformat; Import java.text.numberformat; Import java.text.parseexception; Import java.text.simpledateformat; Import java.util.date; import java.util.locale; org.junit.test; public class i18ntest { /*** resourcebundle:リソースパッケージクラス。 * * 1。ClassPath:basename.propertiesの下に対応するリソースファイルがあります。 Basenameが基本名です。 *2。ベースname_language code_country code.propertiesを使用して、さまざまな国や地域からリソースファイルを追加できます。 i18n_zh_cn.properties * 3。同じベース名を持つすべてのリソースファイルのキーがまったく同じでなければなりません。 *4。Native2asciiコマンドを使用して、漢字ペアのASCコードを取得できます。 Eclipseには組み込みのツールがあります* 5。リソースバンドルのGetBundle(ベース名、ロケールインスタンス)を呼び出してResourceBundleオブジェクト* 6を取得できます。リソースバンドルのGetString(Key)を呼び出してリソースファイルの値文字列を取得できます。 * 7。dateformat、numberformat、messageformatと組み合わせて、国際化を達成できます。 * */ @test public void testresourcebundle(){locale locale = locale.china; ResourceBundle ResourceBundle = resourceBundle.getBundle( "Test"、locale); system.out.println(resourcebundle.getString( "date")); system.out.println(resourcebundle.getString( "Salary"));文字列datelabel = resourcebundle.getString( "date"); string sallabel = resourcebundle.getString( "Salary"); string str = "{0}:{1}、{2}:{3}";日付date = new date(); double sal = 12345.12; dateformat dateformat = dateformat.getDateInstance(dateformat.medium、locale);文字列dateStr = dateformat.format(date); numberformat numberformat = numberformat.getCurrencyInstance(locale); string salstr = numberformat.format(sal);文字列result = messageformat.format(str、datelabel、datestr、sallabel、salstr); system.out.println(result); } / *** messageformat:パターン文字列*パターン文字列:プレースホルダーの文字列: "date:{0}、salary:{1}"*パターン文字列は、フォーマットメソッドを介してフォーマットできます* / @test public void testmessageformat(){string str = "date:{0}、salary:{1}"; locale locale = locale.china;日付date = new date(); double sal = 12345.12; dateformat dateformat = dateformat.getDateInstance(dateformat.medium、locale);文字列dateStr = dateformat.format(date); numberformat numberformat = numberformat.getCurrencyInstance(locale); string salstr = numberformat.format(sal);文字列result = messageformat.format(str、datestr、salstr); system.out.println(result); } /*** numberformat:数値を数値文字列または通貨文字列にフォーマットするためのツールクラス* 1。ファクトリーメソッドを介してナンバーフォーフォームオブジェクトを取得します* numberformat.getNumberInstance(locale); //数字としてフォーマットされた文字列* numberformat.getCurrencyInstance(locale); //通貨としてフォーマットされた文字列**2。フォーマット方法*3。文字列を解析方法から数値タイプに解析します。 */ @test public void testnumberformat()throws 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:SS * IIは、文字列を解析しますdateformat.parse.out.println(日付)。 Locale alocale) * 3。時間のみをフォーマットする日付フォーマットオブジェクトを取得できます:GetTimeInstance(int Style、Locale alocale) * 4。日付と時刻の両方をフォーマットする日付フォーマットオブジェクトを取得できます。ロケールは、国と地域を表すロケールオブジェクト*6。dateFormatのフォーマットメソッドを介して文字列に日付オブジェクトをフォーマットします。 */ @test public void testdateformat(){locale locale = locale.us;日付date = new date(); System.out.println(date); // get dateformat object dateformat dateformat = dateformat.getDateTimeInstance(dateFormat.Long、dateFormat.Medium、locale); string str = dateformat.format(date); System.out.println(str); } /*** Locale:Javaの国または地域を表すクラス。 JDKには多くの定数が提供されています。 * Webアプリケーションでは、Locale(LanguageCode、CountryCode) *を介して作成することもできます。Request.GetLoCale()メソッドを介して取得できます。 */ @test public void testlocale(){locale locale = locale.china; System.out.println(locale.getDisplayCountry()); System.out.println(locale.getLanguage()); locale = new Locale( "en"、 "us"); System.out.println(locale.getDisplayCountry()); System.out.println(locale.getLanguage()); }}上記は、Java Webの国際化の編集です。今後も関連情報を追加し続けます。このサイトへのご支援ありがとうございます!