This method is not working for Android Kitkat, but works in Android Oreo very well.
public String parseDateToTime(String time) {
String inputPattern = "dd/MM/yyyy hh:mm aa";
String outputPattern = "hh:mm aa";
SimpleDateFormat inputFormat = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
inputFormat = new SimpleDateFormat(inputPattern);
}
SimpleDateFormat outputFormat = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
outputFormat = new SimpleDateFormat(outputPattern);
}
Date date = null;
String str = null;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
date = inputFormat.parse(time);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
str = outputFormat.format(date);
}
} catch (ParseException e) {
e.printStackTrace();
}
Log.d("timecon",str);