Hello I am using an android application and I am trying to figure out how to convert a 24 hour time to a 12hour time.
Example
24 hour format 12:18:00
to
12 hour format 12:18pm
17:30 on a 24-hour clock is is 5:30 PM on a 12-hour clock.
Try using a SimpleDateFormat
:
String s = "12:18:00";
DateFormat f1 = new SimpleDateFormat("HH:mm:ss"); //HH for hour of the day (0 - 23)
Date d = f1.parse(s);
DateFormat f2 = new SimpleDateFormat("h:mma");
f2.format(d).toLowerCase(); // "12:18am"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With