gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:30:59 29 4
gpt4 key购买 nike

我在 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 (法语)

你有什么想法吗?

最佳答案

您的问题重复 How to change date format (month name) in iReport?Setting REPORT_LOCALE in IReport?职位。

  • 要在 iReport 中设置语言环境,您应该调用对话框选项 - 编译和执行(通过 iReport -> 工具 -> 选项菜单)。

  • Dialog for setting language

    对于此文本字段:

    <textField pattern="EEEEE dd MMMMM yyyy">
    <reportElement x="0" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
    </textField>

    结果将是:

    Result via preview in iReport

    备注 : 它仅适用于 iReport 中的预览。
  • 对于 Java 应用程序,您可以设置 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);

    结果是:

    The generated report in Adobe Reader

    关于localization - iReport:如何根据法语区域设置格式化日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12636568/

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