Originally posted by Jim Yingst:
I wrote the last post without seen your followup. Try replacing mm with MM, and if the problem persists, tell us what the exception said, and which line it was thrown from. It might also be useful to know what the input values of pattern and actualDate were.
Assuming the user passes in pattern as "MM-dd-YYYY" and userDate as "11/01/2006", the code below will output "Thur Nov 01 16:18:30 EDT 2006" for systemDate but throws an exception for finalDate and I can't see the output.
public String formatDate(String pattern, String userDate)
{
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MM-YYYY");
try{
java.util.Date systemDate = sdf.parse(userDate);
System.out.println(systemDate);
String finalDate = sdf2.format(systemDate);
System.out.println(finalDate);
}
catch (Exception ex) {
System.out.println(ex);
}
return finalDate;
}
[ November 02, 2006: Message edited by: Steven Marco ]