I have tried the code below, but it's not working.
Please explain why it's not working.
public static void main(String[] args) {
String ti = "11:30 PM, Sun 07 Oct 2018";
String sformat = "h:m a, E dd M yyyy";
String cformat = "hh:mm a";
String d = dateFormater(ti, cformat, sformat);
System.out.println(d);
}
public static String dateFormater(String dateFromJSON,
String expectedFormat, String oldFormat) {
SimpleDateFormat dateFormat = new SimpleDateFormat(oldFormat);
Date date = null;
String convertedDate = null;
try {
date = dateFormat.parse(dateFromJSON);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(expectedFormat);
convertedDate = simpleDateFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return convertedDate;
}