Please find the below program to convert dates from one format to another.
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<String> list=new ArrayList<String>();//Creating arraylist
list.add("02-JAN-2020");//Adding object in arraylist
list.add("06-APR-2020");
list.add("09-ARR-2020");
list.add("07-MAY-2020");
int j;
//converted array list into string array
String array[] = new String[list.size()];
for( j =0;j<list.size();j++){
array[j] = list.get(j);
}
DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat inputFormat = new SimpleDateFormat("dd-MMM-yyyy");
//convert the input format to the output format
for (int counter = 0; counter < j; counter++) {
Date date = inputFormat.parse(array[counter]);
String outputText = outputFormat.format(date);
System.out.println(outputText);
}
}
}
While running the program, I'm getting this error: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type ParseException