1. define the class extends to JRDefaultScriptlet
public class ReportScriptlet extends net.sf.jasperreports.engine.JRDefaultScriptlet
// format of strDate: YYYY/MM/DD
public static String getFormatedDate(String strDate,String outputFormat){
try {
// Some examples
SimpleDateFormat formatter = new SimpleDateFormat(INPUT_DATE_FORMAT);
Date date = (Date)formatter.parse(strDate.trim());
formatter.applyPattern(outputFormat);
String formatedDate = formatter.format(date);
System.out.println("formatedDate:" + formatedDate);
return formatedDate;
}catch (Exception e) {
return strDate; // just don't format the String
}
}
2. Added scriptletClass="tnReports.ReportScriptlet" in the report definition file(.jrxml)
3. Use the method defined in the class,e.g.
$P{REPORT_SCRIPTLET}.getFormatedDate((String)$P{REPORT_SCRIPTLET}.getParameterValue("START_DATE"),"MMM dd, yyyy")
Comments
Post a Comment