如何在 JasperReports 中显示具有特定格式和区域设置的日期?

How to display a date with a specific format AND Locale in JasperReports?

这是我的 jrxml 的摘录:

<textField>
    <textFieldExpression><![CDATA["Exported on " + new java.text.SimpleDateFormat("dd-MMM-yyyy HH:mm:ss z").format(new java.util.Date(), java.util.Locale.US)]]></textFieldExpression>
</textField>

我在使用 Jaspersoft Studo 6.0 编译时出现此错误。4.Final:

Errors were encountered when compiling report expressions class file:
1. The method format(Date, StringBuffer, FieldPosition) in the type SimpleDateFormat is not applicable for the arguments (Date, Locale)
            value = "Exported on " + new java.text.SimpleDateFormat("dd-MMM-yyyy HH:mm:ss z").format(new java.util.Date(), java.util.Locale.US); //$JR_EXPR_ID=28$

这看起来很奇怪,因为 SimpleDateFormat 没有任何 format(Date, StringBuffer, FieldPosition) 方法!

糟糕,实际上我没有将 Locale 参数放在正确的方法上,这是正确的 jrxml:

<textField>
    <textFieldExpression><![CDATA["Exported on " + new java.text.SimpleDateFormat("dd-MMM-yyyy HH:mm:ss z", java.util.Locale.US).format(new java.util.Date())]]></textFieldExpression>
</textField>