I have a requirement where I am converting Date into one format to another, I ma getting a unparsable Date Exception. The code for the Class is pasted below
public class DateTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
String stringDate = "Fri Feb 26 14:14:40 CST 2016";
Date date = convertToDate(stringDate);
System.out.println(date);
}
public static Date convertToDate(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Date convertedCurrentDate = null;
try {
convertedCurrentDate = sdf.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
return convertedCurrentDate;
}
}