How can I simply get time, set by the user on time picker widget in android ?
Like this.
timepicker.gettime();
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).
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.
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/
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();
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