【问题标题】:How to display a date with a specific format AND Locale in JasperReports?如何在 JasperReports 中显示具有特定格式和区域设置的日期?
【发布时间】:2015-04-28 15:45:04
【问题描述】:

这是我的 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) 方法!

【问题讨论】:

    标签: jasper-reports simpledateformat date-formatting


    【解决方案1】:

    哎呀其实我没有把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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      • 2018-07-02
      • 2017-01-29
      相关资源
      最近更新 更多