iReport:如何根据法语区域设置格式化日期

2024-02-28

我在格式化日期时遇到问题iReport

我的电脑将区域设置语言配置为French但当iReport生成报告我发现日期格式为English locale.

这是我的一些代码jrxml file :

<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 (in French)

你有什么主意吗?


您的问题重复如何更改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);

结果是:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iReport:如何根据法语区域设置格式化日期 的相关文章

随机推荐