3

我想从TimePickerAndroid 中检索时间并将其存储在适当的变量中。因为我也想将它保存在 SQLite 数据库中。如何轻松检索用户选择的时间?

4

3 回答 3

3
 timePicker.setOnTimeChangedListener( new TimePicker.OnTimeChangedListener() {

            @Override
                public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                    // TODO Auto-generated method stub
                    date = String.valueOf(hourOfDay).toString() + ":" + String.valueOf(minute).toString();
                }

});

这将从 timePicker 中选择的时间保存为 XX:XX

于 2014-08-19T19:36:29.517 回答
0

timePicker.getCurrentHour()和/或timePicker.getCurrentMinute()

于 2013-05-16T06:04:30.130 回答
0

如果你使用 Kotlin,那么你可以试试我为 TimePicker 创建的这个扩展

fun TimePicker.getDate(): Date {
    val calendar = Calendar.getInstance()
    if (Build.VERSION.SDK_INT >= 23) {
        calendar.set(Calendar.HOUR_OF_DAY, hour)
        calendar.set(Calendar.MINUTE, minute)
    } else {
        calendar.set(Calendar.HOUR_OF_DAY, currentHour)
        calendar.set(Calendar.MINUTE, currentMinute)
    }
    return calendar.time
}
于 2020-04-08T10:33:19.273 回答