2

String (returns string :odb.getCloseDate())以下のコードで を Date に変換したいと思います。しかし、このフォーマットでは出力が得られ"23/10/2013"ません。間違いを犯している場所を修正してください。データベーステーブルの値は次の形式です: 2013-06-30 そして、ビーン、つまり odb.getCloseDate() を介してこのデータを取得しています。ここで、この日付をこの形式、つまり 2013 年 10 月 23 日で表示する必要があります。

        HSSFCell row1 = row.createCell((short) j);
        //row1.setCellType(row1.CELL_TYPE_NUMERIC);

        try
        {
            //row1.setCellValue( Date.parse(odb.getCloseDate()));
            DateFormat formatter;
            Date date;
            formatter = new SimpleDateFormat("dd/MM/yyyy");
            row1.setCellValue(date = formatter.parse(odb.getCloseDate()));

        }
        catch (Exception e)
        {
            row1.setCellValue(odb.getCloseDate());
        }
4

2 に答える 2

3

日付と時刻のパターン

mmを示しますMinutesMM示しますMonth

formatter  = new SimpleDateFormat("dd/MM/yyyy");

それ以外の

formatter  = new SimpleDateFormat("dd/mm/yyyy");

これを試して、

        String dateValue = "2013-06-30"; //consider as your date.
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// First apply the patern to the incoming date value. Because it doesnt know the actual incming format
        Date actualDate = simpleDateFormat.parse(dateValue);
        simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
        System.out.println(simpleDateFormat.format(actualDate));
于 2013-10-24T08:20:08.477 に答える
1

あなたの日付形式 mm では MM

理由

m   Minute in hour

一方

M   Month in year

する必要はありMonth in yearませんMinute in hour

次に、フォーフォーマッターは次のようになります

formatter  = new SimpleDateFormat("dd/MM/yyyy");

ここでさまざまなフォーマットを見てください。

于 2013-10-24T08:22:44.473 に答える