5

I am trying to display a java.time.LocalDate in my report with the format :

<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>

But I am getting a date like : 2017-03-09. Is it due to the type java.time.LocalDate?

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
thomas
  • 1,201
  • 2
  • 15
  • 35
  • It looks like the result from `LocalDate.toString()` alright. I don’t know the Jasper Reports answer to this question. In pure Java you would use `LocalDate.format(DateTimeFormatter)`. – Ole V.V. Mar 09 '17 at 14:12
  • 4
    Solved : $F{dateFacture}.format(java.time.format.DateTimeFormatter.ofPattern("EEEE d MMMM yyyy")) – thomas Mar 09 '17 at 16:17
  • @PetterFriberg, the answers to that other question explain how to format a `LocalDateTime` in Java — not a `LocalDate` in a Jasper report. The question is tagged jasper-reports, not java, it may mean that the Jasper report context was the issue for the asker? thomas can best tell. – Ole V.V. Mar 10 '17 at 19:09
  • 1
    I have enhanced this [question](http://stackoverflow.com/questions/38830722/how-to-format-java-time-localdatetime-with-pattern) to include `java.time.LocalDate` and it shows how to do it with pattern that seems to be the initial intention of OP. Note in jasper-reports it's also better to use pattern to have correct format in export to for example excel. – Petter Friberg Mar 10 '17 at 20:54

1 Answers1

4

Just to document that this question has been answered, here’s the solution that the asker reported in a comment:

<textFieldExpression>
    <![CDATA[$F{dateFacture}.format(java.time.format.DateTimeFormatter.of‌​Pattern("EEEE d MMMM yyyy"))]]>
</textFieldExpression>
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161