Search code examples
androidtimepicker

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

Solution

  • 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/