如何在iReport中更改日期格式(月份名称)?

Har*_*wan 2 jasper-reports date-format ireport

我需要在iReport中更改日期格式.目前我使用SQL查询来收集数据.这是我在iReport中的查询

SELECT DATE_FORMAT(CURRENT_DATE,'%d-%m-%Y')AS currentDate,Upper(e.name)AS名称,e.address,Upper(ea.comName)AS comName blablablabla .....

和currentDate字段将显示28-12-2011

要求是将月份(12)改为"Disember"而不是"12月".或者,如果月份是1,那么在报告中应该是"Januari".

月份名称是[Januari,Februari,Mac,April,Mei,Jun,Julai,Ogos,September,Oktober,November,Disember].

我可以在iReport中执行这些条件吗?

提前致谢.

Ale*_*x K 6

您可以创建和使用scriptlet,也可以使用此示例中的表达式:

  • 使用国家区域设置(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>
Run Code Online (Sandbox Code Playgroud)
  • 使用条件? :运算符
<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>
Run Code Online (Sandbox Code Playgroud)
  • 您可以阅读本文如何使用scriptlet.