Date format
To choose from date format available in jasper ireport select Text Field.
- Go to Pattern Property of selected Text Field.
- Click on right icon to select from list.
- You will see Different Category , select Date Category .
- Now different type of Pattern is available for date , select required pattern and click on OK.
For example I have select Pattern dd/MM/yyyy
- Now Click on Preview to run your report.
You can change Pattern at any part of time as per your requirement.
Custom Date format
Sometimes it is required to change date format dynamically.
You can change date format run time dynamically .
- For same you have to create a Parameter of type java.lang.String and its value can be change at run time.
For example I have created a Parameter DateFormat of type java.lang.String.
- Go to Pattern Expr. Property of selected Text Field.
- Click on right icon to Select Parameter.
Using java SimpleDateFormat
You can also use java SimpleDateFormat to required date format.Add following expression in Text Field Expression
new SimpleDateFormat(Date_Format).format(Database_field)
where Date_format is Pattern value as per your requirement
and Database_field is database field which need to be formatted(must be Date data Type).
textField with pattern performers faster than new SimpleDateFormat("Date_Format").format("Database_field").
It's important when you have deal with huge reports.
No comments:
Post a Comment