2011-12-28 201 views
2

我有要求更改iReport中的日期格式。 目前我使用SQL查詢來收集數據。 這是我在iReport的如何在iReport中更改日期格式(月份名稱)?

SELECT DATE_FORMAT查詢(CURRENT_DATE, '%D-%間%Y')AS的currentdate,上(e.name)名稱,e.address, 上(ea.comName )AS comName blablablabla .....

和的currentdate現場將展示28-12-2011

什麼要求更改月份(12) 「Disember」 而不是 「十二月」。或者如果月份是1,那麼報告應該是「Januari」。

本月的名字是[Januari,Februari,Mac,April,Mei,Jun,Julai,Ogos,September,Oktober,November,二月]。

我可以在iReport中做這些條件嗎?

在此先感謝。

回答

6

您可以創建和使用小腳本或者您可以在此樣品中使用這樣的表達式:

  • 使用國家語言環境(ms_MY,馬來西亞):
<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> 
  • 使用條件? :運營商
<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> 
+0

@Hariawan我剛剛添加了新的解決方案 – 2011-12-28 12:00:29

1

要以不同格式顯示日期,其中一個選項是根據區域設置格式化日期。例如,以下表達式使用當前用戶的語言環境:

DateFormat.getDateInstance(DateFormat.LONG, $P{REPORT_LOCALE}).format($F{currentDate}) 
相關問題