Skip to Content
author's profile photo Former Member
Former Member

Jasper Report Date formatting

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 21, 2015 at 07:28 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2015 at 09:20 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.