user3245747
user3245747

Reputation: 937

Date locale in JasperReports

I am writing a program in Java that uses JasperReports to produce reports. One of the fields of the reports is a date field. I send the locale variable as such:

    Map parametersMap = new HashMap();
    parametersMap.put(JRParameter.REPORT_LOCALE, myLocale2);

This is working fine but the problem is that the time is also appearing in the date field. I used the DATE() function in MySQL but I still kept getting the time in my report. I only need the date to show (in the proper locale). If I set the pattern variable in report such that the date is shown in a specific format then the time would not appear, but this would cancel the locale setting and I don't want that. Can someone please tell me how to get rid of the time information?

Upvotes: 1

Views: 5417

Answers (3)

Syaba_dev
Syaba_dev

Reputation: 1

in my country indonesia, i am using this code

parametersMap.put(JRParameter.REPORT_LOCALE, new Locale("id"));

I wish this can help anyone using java EE or java

Upvotes: 0

user3245747
user3245747

Reputation: 937

The answer provided by user1791574 worked fine for me. However, I found a better way especially if the date field appears in a sub report in several records. In that case it would not be possible to send the date as a parameter because we don't know how many records are in the sub report. The solution I found was obtained from http://community.jaspersoft.com/questions/532484/default-date-format-only-date and it consisted of using the following piece of code:

DateFormat.getDateInstance(DateFormat.SHORT, $P{REPORT_LOCALE}).format( $P{MyDateParam} )

Both ways worked fine but this "is more natural" in that jasper reports do the work and not the user through extra lines of code.

Upvotes: 0

user1791574
user1791574

Reputation: 1749

You can try this:

  1. Send your formatted date using param. e.g.:

parametersMap.put("date", new SimpleDateFormat("MMM dd yyyy", Locale.FRANCE) .format(new Date()));

Set this date in your report.

Enjoy.

Upvotes: 2

Related Questions