cancel
Showing results for 
Search instead for 
Did you mean: 

Jasper Report Date formatting

Former Member
0 Kudos

Hi ,

I am facing issue while formatting date/time in specified format using jasper pattern. For Date/Time field, if i am using pattern as dd/MM/yy ,in report data is getting displayed as 09/MM/15 instead 09/10/15 . If i use pattern as dd/mm/yy data is getting formatted incorrectly.Let me know if i am using any wrong format of there is required any additional configuration.

Regards, Ashwini

former_member469962
Contributor
0 Kudos

Hi Ashwini, Could you post the textFieldExpression used to print date from your jrxml?

Regards, Shwetha

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member469962
Contributor
0 Kudos

Hi Ashwini,

Could you remove the pattern attribute from the textfield element and try the below as the textFieldExpression?

 <textFieldExpression class="java.lang.String"><![CDATA[new java.text.SimpleDateFormat("dd/MM/yyyy").format($F{CREATION_DATE})]]></textFieldExpression>

Regards, Shwetha

Former Member
0 Kudos

Hi Shwetha,

I had tried with same approach as you mentioned.It's working fine after exporting the report but if someone wants to change the format using spreadsheet date format as per their need,it's not formatting correctly.

Regards, Ashwini

Former Member
0 Kudos

Hi Shwetha,

Please find text field expression below.

 <fieldname="CREATION_DATE"class="java.sql.Timestamp"/>
 <textField pattern="dd/MM/yyyy">
     <reportElement x="0" y="0" width="89" height="60"/>
         <box>
             <pen lineWidth="0.5"/>
             <topPen lineWidth="0.5"/>
             <leftPen lineWidth="0.5"/>
             <bottomPen lineWidth="0.5"/>
             <rightPen lineWidth="0.5"/>
         </box>
     <textElement textAlignment="Center" verticalAlignment="Middle">
         <font size="8"/>
     </textElement>
     <textFieldExpression class="java.util.Date"><![CDATA[$F{CREATION_DATE}]]></textFieldExpression>
 </textField>

To resolve this issue,i have tried using simple date format and it was formatting correctly.But if i was changing the date format in generated report,it was not incorrectly.