您的问题重复如何更改iReport中的日期格式(月份名称)? https://stackoverflow.com/q/8653424/876298 and 在IReport中设置REPORT_LOCALE? https://stackoverflow.com/q/8847698/876298 posts.
- 用于设置区域设置iReport你应该调用对话框选项 - 编译和执行 (via iReport -> Tools -> Options menu).
为了这文本域:
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
结果将是:
Note:它仅适用于预览iReport.
- 对于 Java 应用程序,您可以设置JRParameter.REPORT_LOCALE http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRParameter.html#REPORT_LOCALE范围。
Map<String, Object> params = new HashMap<String, Object>();
params.put(JRParameter.REPORT_LOCALE, Locale.FRENCH);
JasperFillManager.fillReportToFile(compiledReportName, params);
对于使用这样的代码生成的报告,结果将是相同的。
工作样本,jrxml file:
<?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);
结果是: