【发布时间】:2017-07-30 13:15:56
【问题描述】:
我试图在我的报告中显示java.time.LocalDate,格式为:
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="64" y="0" width="150" height="20" uuid="5e003c53-2327-4f75-9adf-831a3bb494ff"/>
<textElement verticalAlignment="Middle">
<font isBold="true" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{dateFacture}]]></textFieldExpression>
</textField>
但我得到的日期如下:2017-03-09。是 java.time.LocalDate 类型的原因吗?
【问题讨论】:
-
看起来像
LocalDate.toString()的结果好吧。我不知道 Jasper Reports 对这个问题的回答。在纯 Java 中,您将使用LocalDate.format(DateTimeFormatter)。 -
已解决:$F{dateFacture}.format(java.time.format.DateTimeFormatter.ofPattern("EEEE d MMMM yyyy"))
-
@PetterFriberg,其他问题的答案解释了如何在 Java 中格式化
LocalDateTime,而不是在 Jasper 报告中格式化LocalDate。问题标记为 jasper-reports,而不是 java,这可能意味着 Jasper 报告上下文是提问者的问题?托马斯最能说明问题。 -
我已经增强了这个 question 以包含
java.time.LocalDate并且它展示了如何使用似乎是 OP 最初意图的模式来做到这一点。请注意,在 jasper-reports 中,最好使用模式在导出到例如 excel 时使用正确的格式。
标签: java jasper-reports java-time