gpt4 book ai didi

jasper-reports - 如何更改 iReport 中的日期格式(月份名称)?

转载 作者:行者123 更新时间:2023-12-01 14:28:21 32 4
gpt4 key购买 nike

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

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

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

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

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

提前致谢。

最佳答案

您可以创建和使用 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>
  • 使用条件 ? : 运算符
<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>

关于jasper-reports - 如何更改 iReport 中的日期格式(月份名称)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8653424/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com