如何在iReport中更改日期格式(月份名称)? [英] How to change date format (month name) in iReport?

查看:1037
本文介绍了如何在iReport中更改日期格式(月份名称)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've a requirement to change the date format in iReport. Currently I used an SQL query to collect the data. Here's my query in iReport


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

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

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

and currentDate field will show 28-12-2011

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

What the requirement is change the month (12) to "Disember" not "December". Or if the month is 1 so in the report should be "Januari".

月份名称是[Januari,Februari,Mac,April,Mei,Jun,Julai, Ogos,九月,十月,十一月,解密]。

The Month names are [Januari, Februari, Mac, April, Mei, Jun, Julai, Ogos, September, Oktober, November, Disember].

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

Can I do these condition in iReport?

谢谢提前。

推荐答案

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

You can create and use scriptlet or you can use expressions like in this samples:


  • 使用国家区域设置( 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>
    




    • 您可以阅读这篇文章如何使用 scriptlet

      • You can read this article how to use scriptlet.
      • 这篇关于如何在iReport中更改日期格式(月份名称)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆