Skip to content Skip to sidebar Skip to footer

How To Replace Old Getcurrenthour() With New Gethour()?

I have these code and work well to show time from timePicker. the code use getCurrentHour and getCurrentMinute. public void setTime(View view) { int hour = timePicker1.getCur

Solution 1:

You can check SDK version using android.os.Build.VERSION.SDK_INT:

int hour = 0;
intmin = 0;

int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion > android.os.Build.VERSION_CODES.LOLLIPOP_MR1){
    hour = timePicker1.getHour();
    min = timePicker1.getMinute();
} else {
    hour = timePicker1.getCurrentHour();
    min = timePicker1.getCurrentMinute();
}

Solution 2:

Ok, it works well with new time functions getMinute() and getHour() in emulator, So the problem probably cause because of API used. These tow functions require API 23.

Solution 3:

This answer is all you need don't follow other guides. Do the check and then just use timePicker.getCurrentHour and timePicker.getCurrentHour this is for below API 23. For 23 and above use timePicker.getHour and timePicker.getMinute for minutes.

Post a Comment for "How To Replace Old Getcurrenthour() With New Gethour()?"