jorgew.moura Posted February 21, 2018 Share Posted February 21, 2018 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[/code]I tried convert it using:new SimpleDateFormat("yyyyMMdd").parse($F{date})[/code]$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. Link to comment Share on other sites More sharing options...
sergey.vishnevetskiy Posted February 23, 2018 Share Posted February 23, 2018 In a similar situation I had to make scriptlet with thispublic 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));}[/code]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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now