Hi
I'm trying to convert a string that already looks like a date to a
date that I can use when I pass it from java to the database. I
receive the date in format yyyy-mm-dd and I need it to be a date
variable in 'mm/dd/yyyy' or 'm/dd/yyyy' format. My code is shown
below. Any suggestions?
code:
String sailYear = (String)sail_date.toString().substring(0,4);
String sailMonth = (String)sail_date.toString().substring(5,7);
String sailDay = (String)sail_date.toString().substring(8,10);
int monthCutter = Integer.parseInt(sailMonth);
String newMonth = Integer.toString(monthCutter);
String sailingDate =
newMonth.concat("/").concat(sailDay).concat("/").concat(sailYear);
java.text.SimpleDateFormat.getInstance().setLenien t(true);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String str = sdf.format(sailingDate);
Error:
java.lang.IllegalArgumentException: Cannot format given Object as a
Date
Thanks!