I'm studying the iReport Design report tool and, when I tried convert a String object to Date, I received the message:
Error filling print... java.util.Date cannot be cast to java.lang.String
I tried convert it using:
new SimpleDateFormat("yyyyMMdd").parse($F{date})
$F{date} is the String that I get from the query. I try convert it in the Pattern Expr. of Text Field Properties of the $F{date}.
This don't work with Expression Class java.land.String and don't work with java.util.Date.
1 Answer:
Posted on February 23, 2018 at 9:39am
In a similar situation I had to make scriptlet with this
public String toDateFormat (String dateInput, String desiredFormat, String existingFormat ){ SimpleDateFormat sdfOld = new SimpleDateFormat(existingFormat); Date date = null; try { date = sdfOld.parse(dateInput); } catch (ParseException e) { e.printStackTrace(); } SimpleDateFormat sdfNew = new SimpleDateFormat(desiredFormat); return String.valueOf(sdfNew.format(date)); }
to be able affectively manage it. Surely it's reloaded with default formats that I use, to make it simplier, but approach still the same.