change date format : 24 to 12 hours
public static String Convert24to12(String time) {
String convertedTime = "";
try {
SimpleDateFormat displayFormat = new SimpleDateFormat("hh:mm a",Locale.US);
SimpleDateFormat parseFormat = new SimpleDateFormat("HH:mm:ss",Locale.US);
Date date = parseFormat.parse(time);
convertedTime = displayFormat.format(date);
System.out.println("convertedTime : " + convertedTime);
} catch (final ParseException e) {
e.printStackTrace();
}
return convertedTime;
//Output will be 10:23 PM
}
No comments:
Post a Comment