2011-12-28 191 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}) 
相关问题