Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting 24hour time to 12hour time?

Tags:

java

date

android

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
like image 319
ericlee Avatar asked Nov 10 '11 15:11

ericlee


People also ask

What time is 17.30 in 12-hour time?

17:30 on a 24-hour clock is is 5:30 PM on a 12-hour clock.


1 Answers

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"
like image 146
maerics Avatar answered Sep 26 '22 16:09

maerics