0

I am working on project where I need to convert Non English dates to standard JAVA Calender/Date format. For example date like helmikuu 13, 2013 should be converted to 13 February, 2013.

I think its doable using Java Simple Date Format Locate Function. I tried to use this code but it throws Unparseable date: "helmikuu 13, 2013" error.

public static void main(String args[]) throws Exception {
        String dateInFin = "helmikuu 13, 2013";
        Locale localeFi = new Locale("fi", "FI");
        DateFormat dateFormatFin = new SimpleDateFormat("MMMMM dd, yyyy");
        dateFormatFin.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, localeFi);

        System.out.println("Locale: "+localeFi.getDisplayName());
        System.out.println(dateFormatFin.parse(dateInFin));

    }
4

4 に答える 4

4

たとえば、次のようにすることができます (例は、フランス語ロケールからリフアニア語に変換する方法です)。

@Test
    public void testTestLocale() throws Exception {
        Date date = new Date();

        // Get a France locale
        Locale localeFR = Locale.FRANCE;

        // Create a Lithuanian Locale
        Locale localeLT = new Locale("lt", "LT");

        // Get a date time formatter for display in France
        DateFormat fullDateFormatFR =DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,localeFR);

        // Get a date time formatter for display in Lithuania
        DateFormat fullDateFormatLT = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, localeLT);

        System.out.println("Locale: "+localeFR.getDisplayName());
        System.out.println(fullDateFormatFR.format(date));
        System.out.println("Locale: "+localeLT.getDisplayName());
        System.out.println(fullDateFormatLT.format(date));
    }

編集:日付をFinishからUS形式に変換する作業サンプル:

@Test
    public void testConvertDateFromFinToEn() throws Exception {
        String dateInFin = "helmikuu 13, 2013";
        Locale localeFi = new Locale("fi", "FI");

        DateFormat dateFormatFi = new SimpleDateFormat("MMMM dd, yyyy", localeFi);
        // Get Date object
        Date date = dateFormatFi.parse(dateInFin);

        // Convert to US date format
        Locale localeUS = new Locale("en", "US");
        DateFormat dateFormatUS = new SimpleDateFormat("dd MMMM, yyyy", localeUS);

        // Print in US format
        System.out.println(dateFormatUS.format(date));
    }
于 2013-10-18T07:03:19.717 に答える
0

働いた!!

                Locale localeFi = new Locale("fi", "FI");
                SimpleDateFormat dateFormatFin = new SimpleDateFormat("MMMMM dd, yyyy", localeFi);
                System.out.println(dateFormatFin.parse(dateInFin));
于 2013-10-18T07:52:32.923 に答える
0

使用java.text.DateFormat:

DateFormat format = new SimpleDateFormat("MMMM d, yyyy");

parse(String)メソッドとメソッドを使用して、format()日付を解析およびフォーマットします。

于 2013-10-18T07:01:36.803 に答える