2011-12-28 14 views
2

私はiReportで日付形式を変更する必要があります。 現在、データを収集するためにSQLクエリを使用しました。 ここiReportはiReportで日付形式(月名)を変更するには?

名、e.address、 アッパー(ea.comName AS CURRENTDATE、アッパー(e.name)AS

SELECT DATE_FORMAT(CURRENT_DATE、 '%D-%M-%Y')での私のクエリはです)要件は月(12)に "Disember" ではない "12月" に変更され何28-12-2011

が表示されますcomNameのblablablabla .....

とCURRENTDATEフィールドAS。または月が1の場合、レポートでは「Januari」にする必要があります。

月の名前は[Januari、Februari、Mac、April、Mei、Jun、Julai、Ogos、September、Oktober、November、Disember]です。

iReportでこれらの条件を実行できますか?

ありがとうございます。

答えて

6

作成およびスクリプトレットを使用するか、このサンプル中のような表現を使用することができますすることができます:条件付使用

<field name="currentDate" class="java.sql.Timestamp"/> 
... 
<textField> 
    <reportElement x="300" y="0" width="100" height="20"/> 
    <textElement/> 
    <textFieldExpression><![CDATA[(new DateFormatSymbols(new Locale("ms", "MY")).getMonths())[$F{currentDate}.getMonth()]]]></textFieldExpression> 
</textField> 
    • 国家のロケールを使用して(ms_MY、マレーシア) ? :オペレータ
    <field name="currentDate" class="java.sql.Timestamp"/> 
    ... 
    <textField> 
        <reportElement x="200" y="0" width="100" height="20"/> 
        <textElement/> 
        <textFieldExpression><![CDATA[$F{currentDate}.getMonth() == 0 ? 
        "Januari" : $F{currentDate}.getMonth() == 1 ? 
        "Februari" : $F{currentDate}.getMonth() == 2 ? 
        "Mac" : $F{currentDate}.getMonth() == 3 ? 
        "April" : $F{currentDate}.getMonth() == 4 ? 
        "Mei" : $F{currentDate}.getMonth() == 5 ? 
        "Jun" : $F{currentDate}.getMonth() == 6 ? 
        "Julai" : $F{currentDate}.getMonth() == 7 ? 
        "Ogos" : $F{currentDate}.getMonth() == 8 ? 
        "September" : $F{currentDate}.getMonth() == 9 ? 
        "Oktober" : $F{currentDate}.getMonth() == 10 ? 
        "November" : $F{currentDate}.getMonth() == 11 ? 
        "Disember" : "Unknown" 
        ]]></textFieldExpression> 
    </textField> 
    
    • あなたはスクリプトレットを使用する方法this articleを読むことができます。
+0

@ハリアン私はちょうど新しいソリューションを追加しました –

1

異なる形式で日付を表示するには、ロケールに基づいて日付を書式設定することが1つの方法です。たとえば、次の式は現在のユーザーのロケールを使用します。

DateFormat.getDateInstance(DateFormat.LONG, $P{REPORT_LOCALE}).format($F{currentDate}) 
関連する問題