使用此方法转换时间“02:00 PM”=“14:00”此方法适用于 Moto g3、Moto g4、Lenovo K3 note、Samsung Galaxy J3 ..请帮我解决此问题...
public static String convertTimeto24hours(String time) {
String timein24hours = "";
try {
SimpleDateFormat displayFormat = new SimpleDateFormat("HH:mm");
SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a");
Date date = null;
try{
date = parseFormat.parse(time);
System.out.println(parseFormat.format(date) + " = " + displayFormat.format(date));
}catch (ParseException e){
e.printStackTrace();
}
timein24hours = "" + displayFormat.format(date);
return timein24hours;
} catch (Exception e) {
print(e);
Log.error("convertTimeto24hours",e);
}
return timein24hours;
}