Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IllegalArgumentException

Status
Not open for further replies.

dcusick

Technical User
Aug 9, 2000
271
US
What's up all? I am having a problem with a function I created. I have an array of dates, and I'm simply trying to format them in mm/dd/yyyy format. This is my function.

public String[] convertToDate(Object[] objArray) {
int i;
String[] tmpArray = new String[objArray.length];
Date d;
Format df = new SimpleDateFormat("MM/dd/yyyy");
for (i=0; i<objArray.length; i++) {
try {
if ((objArray[ i ]!=null) && (objArray[ i].toString()!=&quot;&quot;)) {
d = Date.valueOf(objArray[ i].toString());
tmpArray[ i]=df.format(d);
} else {
tmpArray[ i]=&quot;&quot;;
}
} catch (IllegalArgumentException s) {
System.out.println(&quot;Illegal Date Format&quot;);
}
}
return tmpArray;
} //End convertToDate()

The problem is, when I get to the line... d = Date.valueOf(objArray[ i].toString());... my program throws an IllegalArgumentException.. Any ideas on what I'm doing wrong?
 
java.sql.Date requires the string coming in to be in a specific format (yyyy-mm-dd). You might check to verify that your array coming in is composed of strings in that format.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top