14

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

Like this.

timepicker.gettime();
Sharjeel
  • 145
  • 1
  • 2
  • 8
  • possible duplicate of [Android: How to get the time from a TimePicker when it is typed in](http://stackoverflow.com/questions/3992820/android-how-to-get-the-time-from-a-timepicker-when-it-is-typed-in) – Andrew T. Mar 10 '14 at 07:14
  • timepicker.clearfocus() solved my problem. – Sharjeel Mar 10 '14 at 07:37

2 Answers2

18

Try it like below.

Java

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();

Kotlin

For picking hour you can use

timePicker.hour;

and for picking minutes you can use

timePicker.minute;

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

int hour = timePicker.hour;
int minute = timePicker.minute;

for more information you can refer to this link

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

Leonardo Sibela
  • 1,613
  • 1
  • 18
  • 39
user3395743
  • 293
  • 2
  • 12
12

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();
reza.cse08
  • 5,938
  • 48
  • 39