Question Detail

Do I want to convert the given CDT formatted 24 hr string into CDT formatted 12 hr, How to convert a 24 hr format string into 12 hr format string?


Thread Reply

Anonymous

- 1 years ago

you can try using a SimpleDateFormat object to convert the time formats.

final String time = "22:15:12";

try {
    final SimpleDateFormat dateformatObj = new SimpleDateFormat("H:mm");
    final Date dateObj = dateformatObj.parse(time);
    System.out.println(dateObj);
    System.out.println(new SimpleDateFormat("K:mm:ss").format(dateObj));
} catch (final ParseException e) {
    e.printStackTrace();
}