Metalhead1247
Metalhead1247

Reputation: 1978

timepicker:- how to get am and pm displayed?

My app has timepicker to select time im able to get hours and minutes, which is then sent through a sms programmatically, Im able to send the hours and minutes using

getCurrentHour()

getCurrentMinute()

How do i get the Am and Pm from the timepicker? is it possible? im not using dialog,directly using timepicker

I want the time to be in this format eg. 4:30PM

Upvotes: 0

Views: 1133

Answers (1)

AAnkit
AAnkit

Reputation: 27549

The hourOfDay will always be 24-hour. If you opened the dialog with is24HourView set to false, the user will not have to deal with 24-hour formatted times, but Android will convert that to a 24-hour time when it calls onTimeSet().

Source :- 1) How to get AM/PM from time picker

2) second way of doing the same

You can always convert 24 hour format to 12 hour format do something like below

String s = "12:18:00";
DateFormat f1 = new SimpleDateFormat("hh:mm:ss");
Date d = f1.parse(s);
DateFormat f2 = new SimpleDateFormat("h:mma");
f2.format(d).toLowerCase(); // "12:18am"

go through this doc also

Upvotes: 2

Related Questions