我在 iReport
中格式化日期时遇到问题我的电脑我将语言环境语言配置为法语但是当 iReport 生成报告时,我发现使用英语语言环境格式化日期。
以下是我的 jrxml 文件中的一些代码:
<band height="41" splitType="Stretch">
<textField pattern="dd/MM/yyyy h.mm a">
<reportElement uuid="fb711e77-c949-4a99-9b52-109aae00c8ed" x="87" y="19" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{datenow}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="51fb76a0-829e-4c36-b474-3ff9c7d4c239" x="41" y="19" width="48" height="20"/>
<textElement>
<font isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Fes Le : ]]></text>
</staticText>
</band>
以下是我的显示方式: Fri Sep 28 09:59:00
我的目标格式为: vendredi 28 septembre 2012 09:59
(法语)
你有什么想法吗?
答案 0 :(得分:3)
您的问题会重复How to change date format (month name) in iReport?和Setting REPORT_LOCALE in IReport?个帖子。
对于此 textField :
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
结果将是:
注意:它仅适用于 iReport 中的预览。
JRParameter.REPORT_LOCALE
参数。Map<String, Object> params = new HashMap<String, Object>();
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH);
JasperFillManager.fillReportToFile(compiledReportName, params);
对于使用此类代码生成的报告,结果将相同。
工作样本 jrxml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... whenNoDataType="AllSectionsNoDetail" ...>
<parameter name="date" class="java.util.Date" isForPrompting="false">
<defaultValueExpression><![CDATA[new Date()]]></defaultValueExpression>
</parameter>
<title>
<band height="50">
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="200" y="11" width="228" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Java代码:
Map<String, Object> params = new HashMap<String, Object>();
params.put("date", new Date());
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH);
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, outputFile);
结果是: