Search code examples
javamysqljasper-reports

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?


Solution

  • 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.