How to set a desired date format for date input controls / filters, and for the fields including date data across JasperReports Server

Solution:
Let's say we want our date format to be MM/dd/yyyy. To set this date format for date input controls / filters, and for the fields including date data across JasperReports Server, we would need to make changes in the following 3 configuration files:
1. jasperreports.properties file (/WEB-INF/classes)

2. adhoc_masks.properties file (/WEB-INF/bundles)

3. jasperserver_config.properties file (/WEB-INF/bundles)

Now that we know which all files are required to achieve our requirement, let's see what changes we need to make in each of these files:

jasperreports.properties file (/WEB-INF/classes):

This file is required to change the date format for .jrxml reports having date fields. To define the global date format for .jrxml reports in the jasperreports.properties file, follow below steps:

1. Open the jasperreports.properties file in an editor.

2. Search for the properties net.sf.jasperreports.text.pattern.date and net.sf.jasperreports.text.pattern.datetime, and define the desired date and date time format to these properties, respectively. For our example date format of MM/dd/yyyy, the properties would look like:
.
net.sf.jasperreports.text.pattern.date=MM/dd/yyyy
net.sf.jasperreports.text.pattern.datetime=MM/dd/yyyy HH:mm:ss

3. Save the file.

4. Restart the application server for the changes to reflect.

adhoc_masks.properties file (/WEB-INF/bundles):

For Ad Hocs, we can define the desired date format in the adhoc_masks.properties file (/WEB-INF/bundles). To do this, follow below steps:
1. Open the adhoc_masks.properties file in an editor.

2. Define the desired date format next to the current last ADH_100_MASK_date_x property, for example:

ADH_100_MASK_date_0 = medium,hide
ADH_100_MASK_date_1 = short,hide
ADH_100_MASK_date_2 = long,hide
ADH_100_MASK_date_3 = MM/dd/yyyy

For defining a desired date timestamp format in addition to the above date format for Ad Hocs, in the same adhoc_masks.properties file, add desired ADH_100_MASK_timestamp_x next to the current last ADH_100_MASK_timestamp, like:

ADH_100_MASK_timestamp_0 = medium,hide
ADH_100_MASK_timestamp_1 = short,hide
ADH_100_MASK_timestamp_2 = long,hide
ADH_100_MASK_timestamp_3 = medium,medium
ADH_100_MASK_timestamp_4 = hide,medium
ADH_100_MASK_timestamp_5 = MM/dd/yyyy HH:mm:ss

3. Save the file.

4. Restart the application server for the changes to reflect.

jasperserver_config.properties file (/WEB-INF/bundles):

For input controls and filters, and data value to display in the desired date format, in addition to making changes to the above 2 files, we also need to make changes in the jasperserver_config.properties file (/WEB-INF/bundles). To get the desired date format as MM/dd/yyyy, follow below steps:
1. Open the jasperserver_config.properties file in an editor.

2. Define the values for the properties date.format, datetime.format, and time.format as below:
date.format=MM/dd/yyyy
datetime.format=MM/dd/yyyy HH:mm:ss
time.format=HH:mm:ss

The above configuration is used for parsing and formatting dates by the server

3. Next, define the calendar.date.format, calendar.datetime.format, and calendar.time.format properties as below:
calendar.date.format=mm/dd/yy
calendar.datetime.format=mm/dd/yy HH:mm:ss
calendar.time.format=HH:mm:ss

These are used for parsing and formatting dates by the calendar component (UI).

4. Save the file.

5. Restart the application server for the changes to reflect.

In the last configuration file, jasperserver_config.properties, please note how we have defined the values for the calendar properties to have the date format displayed as MM/dd/yyyy when we select a value from the calendar picker on the UI.

Calendar component date patterns are different from the patterns used on the server (date.format, datetime.format, and time.format). We need to carefully define the values for the calendar.date.format, calendar.datetime.format, and calendar.time.format properties to have the desired date format displayed once we have selected our date value from the calendar picker on the UI, else we may face some error.

The format for calendar component can be combinations of the following:
# d - day of month (no leading zero)
# dd - day of month (two digit)
# o - day of year (no leading zeros)
# oo - day of year (three digit)
# D - day name short
# DD - day name long
# m - month of year (no leading zero)
# mm - month of year (two digit)
# M - month name short
# MM - month name long
# y - year (two digit)
# yy - year (four digit)

So, for our example of server pattern MM/dd/yyyy, the values for the properties - calendar.date.format, calendar.datetime.format, and calendar.time.format - should be defined as below:

Hope this detailed explanation helps you to achieve your desired date format on JasperReports Server. Thank you for your time and attention to this article.
___________________________________________________________________________
___________________________________________________________________________
Ref. Case #02092110