我想从Android的TimePicker
中检索时间,并将其存储在适当的变量中。同时,我还想将其保存在SQLite数据库中。有什么简单方法可以获取用户选择的时间吗?
我想从Android的TimePicker
中检索时间,并将其存储在适当的变量中。同时,我还想将其保存在SQLite数据库中。有什么简单方法可以获取用户选择的时间吗?
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();
}
});
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
}
timePicker.getCurrentHour()
和/或 timePicker.getCurrentMinute()