Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get time using time picker android

How can I simply get time, set by the user on time picker widget in android ?

Like this.

timepicker.gettime();
like image 482
Sharjeel Avatar asked Mar 10 '14 07:03

Sharjeel


People also ask

What is time and date picker in Android?

Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).

Which method is used to set 24 hrs in TimePicker dialog box?

setIs24HourView(Boolean is24HourView): This method is used to set the mode of the Time picker either 24 hour mode or AM/PM mode. In this method we set a Boolean value either true or false.


2 Answers

Try it like below.

For picking hour you can use

timePicker.getCurrentHour();

and for picking minutes you can use

timePicker.getCurrentMinute();

and then you can set this hour and minute to any Integer variable. Like

int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();

for more information you can refer to this link

http://www.mkyong.com/android/android-time-picker-example/

like image 165
user3395743 Avatar answered Sep 21 '22 20:09

user3395743


If you are using below API 23. then you can use

int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();

And after 23 you can use both

int hour = timePicker.getHour();
int minute = timePicker.getMinute();
like image 41
reza.cse08 Avatar answered Sep 21 '22 20:09

reza.cse08